Показать название страны в приложении - PullRequest
0 голосов
/ 05 мая 2018

Когда я пытаюсь увидеть текущее название страны в браузере, я получаю уведомление на консоли. Есть какой-то метод или альтернатива, чтобы показать мне это в моем tests.html, как в поле ввода (в браузере)? С другой стороны, если существует другая альтернатива для отображения фактического названия страны, пожалуйста, сообщите мне.

tests.ts

import { Component, ViewChild, ElementRef } from "@angular/core";
import { NavController, IonicPage, NavParams } from "ionic-angular";
import {
  NativeGeocoder,
  NativeGeocoderReverseResult
} from "@ionic-native/native-geocoder";
import { Geolocation } from "@ionic-native/geolocation";

declare var google;

@IonicPage()
@Component({
  selector: "page-tests",
  templateUrl: "tests.html"
})
export class TestsPage {
  @ViewChild("mapSmall") mapElement: ElementRef;

  map: any;
  message: any;
  location: any;
  gmLocation: { lat: number; lng: number } = { lat: 0, lng: 0 };

  constructor(
    public navCtrl: NavController,
    private geolocation: Geolocation,
    private nativeGeocoder: NativeGeocoder,
    public navParams: NavParams,
  ) {
    this.onLocateUser();
  }

  onLocateUser() {
    this.geolocation
      .getCurrentPosition()
      .then(location => {
        console.log(
          "position gotten: long:",
          location.coords.longitude,
          " lat:",
          location.coords.latitude
        );
        this.location = location;
        this.gmLocation.lat = location.coords.latitude;
        this.gmLocation.lng = location.coords.longitude;
        this.nativeGeocoder.reverseGeocode(location.coords.latitude,location.coords.longitude)
  .then((result: NativeGeocoderReverseResult) => console.log(JSON.stringify(result.countryName)))
  .catch((error: any) => console.log(error));
      })
      .catch(error => {
        console.log("Error getting location", error);
      });
  }

  ionViewDidLoad() {
    let latlng = new google.maps.LatLng(
      this.gmLocation.lat,
      this.gmLocation.lat
    );
    setTimeout(() => {
      this.loadMap(latlng);
      this.addMarker(this.gmLocation.lat, this.gmLocation.lng);
    }, 100);
  }

  ...

}
...