在angular-google-maps中将地址转换为lat / lon

时间:2014-07-25 17:59:31

标签: javascript angularjs google-maps google-maps-api-3

我正试着站稳脚跟,所以如果这真的很容易原谅我作为一个n00b。

我想使用angular-google-maps并且我在客户端有地址(当前没有存储lat和lon)并且想要显示地址的地图。当我有lat和lon时,它看起来很简单:

angular.module('myApplicationModule', ['google-maps']);

$scope.map = {
   center: {
    latitude: 45,
    longitude: -73
   },
   zoom: 8
};

//html
<google-map center="map.center" zoom="map.zoom"></google-map>

所以我只是错过了将地址转换为lat和lon的步骤,感谢您的建议。

2 个答案:

答案 0 :(得分:1)

要转换为普通地址(我认为这不是您在此处处理的谷歌地图位置对象,只是一个普通的字符串地址)到纬度/经度,您需要使用Google geocoding library。这将返回一个具有geometry属性的对象 - 这将包含您的纬度和经度。

答案 1 :(得分:0)

这是一个directive,它在地图上显示地址并显示。