简体   繁体   English

使用 Google Maps Javascript API 查找最近的地点?

[英]Find the closest places using Google Maps Javascript API?

I'm creating a website and on this website I need to add a map and the user can type any address and it will return the closest place out of a list of places.我正在创建一个网站,在这个网站上我需要添加一张地图,用户可以输入任何地址,它将从地点列表中返回最近的地点。 I have the API imported to my code, but I'm not a very skilled JavaScript programmer so I have no idea how to create this funcionallity.我将 API 导入到我的代码中,但我不是一个非常熟练的 JavaScript 程序员,所以我不知道如何创建这个功能。 From what I've searched, it has to loop through an array of places to find the closest one.从我搜索的内容来看,它必须遍历一系列位置才能找到最接近的位置。

Does anyone have any clue?有没有人有任何线索? Thank you in advance.先感谢您。

You would want to use Places API and do Radar Search Request您可能想要使用 Places API 并执行雷达搜索请求

A Radar Search lets you search for places within a specified search radius by keyword, type or name雷达搜索可让您按关键字、类型或名称搜索指定搜索范围内的地点

service = new google.maps.places.PlacesService(map);
service.radarSearch(request, callback);

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

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