我正在开发一个网站,我需要一个文本框,其中预填充了Google地方信息中最近的城市。我目前正在使用自动填充功能来搜索附近的位置,这确实需要浏览器的位置许可,但是我如何使用API本身搜索附近的城市,而又不必费心从浏览器获取用户的位置并将其传递给Google Places API调用?由于Google无论如何已经从浏览器获取了我的位置,难道它不应该(从逻辑上)只是搜索相对于我当前位置的附近位置nearbySearch
,还是还有其他方法?
好的,
我最终从本机获取了位置,然后将位置传递给Places API,因为Places API显然没有这种(非常基本的)功能。这是我的位置信息:
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function (position) {
var pos = {
lat: position.coords.latitude,
lng: position.coords.longitude
};
//service is a PlacesService instance.
var req = {
location: pos,
radius: '50000',
types: ['(cities)']
};
service.nearbySearch(req, function (results, status) {
...
});
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句