Google Api 获取最近的位置

发布于 2024-10-20 23:41:22 字数 86 浏览 1 评论 0 原文

我想通过传递位置地址来获取最近位置的列表。 例如:洛杉矶,应该以 json 或 xml 格式给我附近所有位置的列表 有没有用于此目的的 Google api?

I want to get the List of nearest locations of by passing an address of location.
like: Los Angeles, should give me the list of all locations near to it either in json or xml format
Is there any Google api for that purpose?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

深居我梦 2024-10-27 23:41:22

Google Places API 包含给定点附近的地点列表。例如,您可以搜索英国伦敦修道院花园附近的书店。 很好的示例可以在 < a href="http://code.google.com/apis/maps/documentation/javascript/places.html#place_search_requests" rel="noreferrer">Google Maps Javascript API V3 地点库文档。

您还可以使用 Geonames.org 数据转储 并滚动您自己的地理查询或使用他们的 REST API。使用他们的数据库,您可以搜索各种类型的地理实体(请参阅要素代码)。

大多数现代 SQL Server 部署都有一些地理空间支持,通常使用某种半正矢公式来查找结果如果您想下载数据转储,请在附近。

但是,如果您只想使用他们的公共 REST API,您会发现他们已经有 查找附近的地名方法,该方法采用要素代码和各种其他搜索参数并返回 XML 或 JSON。

这应该使您能够 如果您愿意的话,搜索旧金山 50 公里范围内的直升机场

如果您想结合 Google 地图查看此操作的实际效果,请参阅我刚刚整理的内容(您需要拥有自己的 Geonames 帐户)。 如果发生僵尸袭击,您应该避开旧金山的以下墓地

Google Places API has lists of places near a given point. For example you can search for bookshops near Convent Garden, London, UK. A good example can be found in the Google Maps Javascript API V3 Places Library documentation.

You can also use the Geonames.org data dump and roll your own geo queries or use their REST API. Using their database you can search for various types of geographical entities (see feature codes).

Most modern SQL Server deployments have some geospatial support, usually using some flavour of the Haversine Formula to find results nearby should you wish to download the data dump.

However, if you just want to use their public REST API you will find that they already have a Find Nearby Toponym method, that takes a Feature Code and various other search parameters and returns XML or JSON.

That should enable you to search for heliports within 50 km of San Francisco should you so wish!

If you would like to see this in action, in combination with Google Maps, here is something I just threw together (you'll need you own Geonames account). In case of a zombie attack you should avoid the following cemeteries in San Francisco.

方圜几里 2024-10-27 23:41:22

“Google Geocoding API”这可以帮助您通过传递地址找到最近位置的列表。
作为参考,请访问此链接

http://code.google.com/apis/maps/documentation/geocoding/

您可以通过传递地址来使用此 API。也可以通过传递纬度和经度等坐标来查找列表

'Google Geocoding API' this could help you to find the list of nearest locations by passing the address.
for reference go to this link

http://code.google.com/apis/maps/documentation/geocoding/

You can use this API by passing the address. It can be also possible to find the list by passing the co-ordinates like latitude and longitude

笑着哭最痛 2024-10-27 23:41:22

我想您可能指的是已弃用的 LocalSearch API - 它是 <立即使用 href="http://code.google.com/apis/maps/documentation/places/" rel="nofollow">Places API。

I think you might mean LocalSearch API which is deprecated - it's Places API now.

皇甫轩 2024-10-27 23:41:22

请参考下面的代码以正确理解脚本中提到的 API
链接来自我获得了代码并帮助我理解。
https://www.geodatasource.com/developers/javascript

function distance(lat1, lon1, lat2, lon2, unit) {
    var radlat1 = Math.PI * lat1/180
    var radlat2 = Math.PI * lat2/180
    var theta = lon1-lon2
    var radtheta = Math.PI * theta/180
    var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
    if (dist > 1) {
        dist = 1;
    }
    dist = Math.acos(dist)
    dist = dist * 180/Math.PI
    dist = dist * 60 * 1.1515
    if (unit=="K") { dist = dist * 1.609344 }
    if (unit=="N") { dist = dist * 0.8684 }
    return dist
}

var data = [{
    "code": "0001",
    "lat": "1.28210155945393",
    "lng": "103.81722480263163",
    "location": "Stop 1"
}, {
    "code": "0003",
    "lat": "1.2777380589964",
    "lng": "103.83749709165197",
    "location": "Stop 2"
}, {
    "code": "0002",
    "lat": "1.27832046633393",
    "lng": "103.83762574759974",
    "location": "Stop 3"
}];

var LocNear= "";
var poslat = 1.28210155945393;
var poslng = 103.81722480263163;

for (var i = 0; i < data.length; i++) {
    // if this location is within 0.1KM of the user, add it to the list
    if (distance(poslat, poslng, data[i].lat, data[i].lng, "K") <= 0.1) {
        LocNear+= '<p>' + data[i].location + ' - ' + data[i].code + '</p>';
    }
}

$('#nearbystops').append(LocNear);

Please refer this code below to understand properly along with API mentioning in script
Link from I got the code and helped me to understand.
https://www.geodatasource.com/developers/javascript

function distance(lat1, lon1, lat2, lon2, unit) {
    var radlat1 = Math.PI * lat1/180
    var radlat2 = Math.PI * lat2/180
    var theta = lon1-lon2
    var radtheta = Math.PI * theta/180
    var dist = Math.sin(radlat1) * Math.sin(radlat2) + Math.cos(radlat1) * Math.cos(radlat2) * Math.cos(radtheta);
    if (dist > 1) {
        dist = 1;
    }
    dist = Math.acos(dist)
    dist = dist * 180/Math.PI
    dist = dist * 60 * 1.1515
    if (unit=="K") { dist = dist * 1.609344 }
    if (unit=="N") { dist = dist * 0.8684 }
    return dist
}

var data = [{
    "code": "0001",
    "lat": "1.28210155945393",
    "lng": "103.81722480263163",
    "location": "Stop 1"
}, {
    "code": "0003",
    "lat": "1.2777380589964",
    "lng": "103.83749709165197",
    "location": "Stop 2"
}, {
    "code": "0002",
    "lat": "1.27832046633393",
    "lng": "103.83762574759974",
    "location": "Stop 3"
}];

var LocNear= "";
var poslat = 1.28210155945393;
var poslng = 103.81722480263163;

for (var i = 0; i < data.length; i++) {
    // if this location is within 0.1KM of the user, add it to the list
    if (distance(poslat, poslng, data[i].lat, data[i].lng, "K") <= 0.1) {
        LocNear+= '<p>' + data[i].location + ' - ' + data[i].code + '</p>';
    }
}

$('#nearbystops').append(LocNear);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文