【发布时间】:2017-05-29 13:57:53
【问题描述】:
我将如何从地址中获取纬度和经度?
我当前的方法是将地址传递给 google maps api:
getLocationJson(term: string) {
var term = "Mechelsesteenweg+64";
return this._http.get('https://maps.googleapis.com/maps/api/geocode/json?address=Someroad+64&key=AIzkeystuffjXDm6eU5mPP9Nczg')
.subscribe((json: any) => {
var obj = JSON.parse(json);
var jsonParsed = obj["results"];
});
}
但我觉得这不是正确的方法。我可以为此使用地理编码器吗?比如:
getGeoLocation(address: string) {
let geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': address }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latlng = google.maps.location.LatLng();
} else {
alert('Geocode was not successful for the following reason: ' + status);
}
});
}
提前致谢。 (基本上是this question,但是反过来了)
【问题讨论】:
标签: angular typescript google-maps-api-3