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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24746622/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 03:18:25  来源:igfitidea点击:

get the coordinates(latitude and longitude) of google map by street address - angular

javascriptjqueryangularjsgoogle-mapsgoogle-maps-api-3

提问by Matan Gubkin

so i have random street address, lets say: 5707 dogwood ave. all i want is to get the coordinates of that address so i can view my google map at the street location using angular. i've search but wasn't able to find anything useful.

所以我有随机的街道地址,可以说:5707 dogwood ave。我想要的只是获取该地址的坐标,以便我可以使用 angular 在街道位置查看我的谷歌地图。我已经搜索过,但找不到任何有用的东西。

the map code(very basic map)

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

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

html code:

html代码:

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

回答by ForgetfulFellow

You can use an http.get as such to make a GET request at Google's API endpoint and retrieve a json of the address's coordinates:

您可以使用 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);
    });

and you can call out the data at $scope.mapData

你可以在 $scope.mapData

Refer to this StackOverflow post for more info: Google Maps API - Get Coordinates of address

有关详细信息,请参阅此 StackOverflow 帖子: Google Maps API - Get Coordinates of address

回答by Matt T.

Assuming you have the address you can use the Google Geocoding web service to manually retrieve the location coordinates. (I added a city and state to better refine the data) https://developers.google.com/maps/documentation/geocoding/

假设您有地址,您可以使用 Google Geocoding Web 服务手动检索位置坐标。(我添加了一个城市和州以更好地优化数据) https://developers.google.com/maps/documentation/geocoding/

JSON:

JSON:

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

XML:

XML:

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

Alternately there is a javascript wrapper on the API

或者,API 上有一个 javascript 包装器

I would also review this post regarding how to deal with rate limiting if you will be exceeding 2,500 requests per day.

如果您每天的请求超过 2,500 个,我还会查看这篇关于如何处理速率限制的帖子。

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

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