简体   繁体   English

谷歌地图(javascript API):从地址获取GPS坐标

[英]Google Maps (javascript API): get GPS coordinates from address

I need to calculate the distance between two addresses and I don't need a map view or anything graphical. 我需要计算两个地址之间的距离,我不需要地图视图或任何图形。

I simply want the user to type in the address (end location is defined by myself) and let the javascript calculate the distance between the two points. 我只是希望用户输入地址(结束位置由我自己定义)并让javascript计算两点之间的距离。

However I don't find a way to send an address string and get the GPS-coordinates from it using the Google Maps API. 但是,我找不到使用Google Maps API发送地址字符串并从中获取GPS坐标的方法。

(I really only need the two GPS points, the distance calculation is trivial.) (我真的只需要两个GPS点,距离计算是微不足道的。)

What you are trying to do is called geocoding. 您要做的是称为地理编码。 It is possible with the Maps API. 可以使用Maps API。 See the Geocoding section for more details. 有关详细信息,请参阅地理编码部分 This is the basic idea: 这是基本的想法:

var geocoder = new google.maps.Geocoder();
geocoder.geocode({
    "address": inputAddress
}, function(results) {
    console.log(results[0].geometry.location); //LatLng
});

However , you are limited to 2500 geocoding requests a day, and what you are trying to do is against the terms of use: 但是 ,您每天只能处理2500个地理编码请求,而您尝试执行的操作违反了使用条款:

Note: the Geocoding API may only be used in conjunction with a Google map; 注意:地理编码API只能与Google地图结合使用; geocoding results without displaying them on a map is prohibited. 禁止在地图上显示地理编码结果。

This page describes a Google JSON service that you can extract gps coordinates from. 此页面描述了可以从中提取gps坐标的Google JSON服务。 I think this would also be under the "No Use of Content without a Google Map" in the TOS. 我认为这也将在TOS中的“没有使用谷歌地图的内容”之下。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM