通过街道地址获取谷歌地图的坐标(纬度和经度)- Angular

6

我有一个随机的街道地址,比如:5707 dogwood ave。我想要获取该地址的坐标,以便使用Angular在地图上查看该地点。

我已经搜索过了,但没有找到有用的信息。

地图代码(非常基本的地图)

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

HTML 代码:

<google-map class="full-image" center="map.center" zoom="map.zoom"></google-map>

我们的任何答案都有帮助到您吗? - ForgetfulFellow
2个回答

7

您可以使用以下http.get来在Google的API端点上进行GET请求,并检索地址坐标的json:

$http.get('http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&sensor=false').success(function(mapData) {
      angular.extend($scope, mapData);
    });

你可以调用$scope.mapData来获取数据。

欲了解更多信息,请参考此StackOverflow帖子: Google Maps API - Get Coordinates of address


这还能用吗?console.log($scope.mapData)输出“undefined”...? - binoculars

1
假设您拥有地址,可以使用Google Geocoding Web服务手动检索位置坐标。(我添加了城市和州以更好地细化数据) https://developers.google.com/maps/documentation/geocoding/ JSON:
http://maps.google.com/maps/api/geocode/json?address=5707%20dogwood%20ave.%20Rosamond,%20CA&sensor=false

XML:

http://maps.google.com/maps/api/geocode/xml?address=5707%20dogwood%20ave.%20Rosamond,%20CA&sensor=false

API还有一个JavaScript包装器可供使用。

如果您每天的请求次数超过2,500次,建议阅读此帖子以了解如何处理速率限制。

http://www.benbybenjacobs.com/blog/2013/09/11/google-geocoding-service-for-angularjs


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接