Ionic4 我想知道谷歌地图io 4的方向
我已经能够实现谷歌地图显示当前,但我想得到一个特定的经度和纬度方向,这将是硬编码请我怎么做,下面是我的打字脚本代码Ionic4 我想知道谷歌地图io 4的方向,ionic4,Ionic4,我已经能够实现谷歌地图显示当前,但我想得到一个特定的经度和纬度方向,这将是硬编码请我怎么做,下面是我的打字脚本代码 import { Component, ViewChild, ElementRef } from "@angular/core"; import { Geolocation } from "@ionic-native/geolocation/ngx"; import { NativeGeocoder, NativeGeoco
import { Component, ViewChild, ElementRef } from "@angular/core";
import { Geolocation } from "@ionic-native/geolocation/ngx";
import {
NativeGeocoder,
NativeGeocoderResult,
NativeGeocoderOptions,
} from "@ionic-native/native-geocoder/ngx";
declare var google;
@Component({
selector: "app-dashboard",
templateUrl: "./dashboard.page.html",
styleUrls: ["./dashboard.page.scss"],
})
export class DashboardPage {
@ViewChild("map", { static: false }) mapElement: ElementRef;
start = "chicago, il";
map: any;
address: string;
latitude: number;
longitude: number;
constructor(
private geolocation: Geolocation,
private nativeGeocoder: NativeGeocoder
) {}
ngOnInit() {
this.loadMap();
}
loadMap() {
this.geolocation
.getCurrentPosition()
.then((resp) => {
this.latitude = resp.coords.latitude;
this.longitude = resp.coords.longitude;
let latLng = new google.maps.LatLng(
resp.coords.latitude,
resp.coords.longitude
);
let mapOptions = {
center: latLng,
zoom: 17,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
this.getAddressFromCoords(resp.coords.latitude, resp.coords.longitude);
this.map = new google.maps.Map(
this.mapElement.nativeElement,
mapOptions
);
this.map.addListener("dragend", () => {
this.latitude = this.map.center.lat();
this.longitude = this.map.center.lng();
this.getAddressFromCoords(
this.map.center.lat(),
this.map.center.lng()
);
});
})
.catch((error) => {
console.log("Error getting location", error);
});
}
getAddressFromCoords(lattitude, longitude) {
console.log("getAddressFromCoords " + lattitude + " " + longitude);
let options: NativeGeocoderOptions = {
useLocale: true,
maxResults: 5,
};
this.nativeGeocoder
.reverseGeocode(lattitude, longitude, options)
.then((result: NativeGeocoderResult[]) => {
this.address = "";
let responseAddress = [];
for (let [key, value] of Object.entries(result[0])) {
if (value.length > 0) responseAddress.push(value);
}
responseAddress.reverse();
for (let value of responseAddress) {
this.address += value + ", ";
}
this.address = this.address.slice(0, -2);
})
.catch((error: any) => {
this.address = "Address Not Available!";
});
}
}
请我想这个代码被修改为答案请,如果可能的话,以显示时间之间的距离,我在离子4角使用这个