Javascript Google Maps API 是否提供按名称搜索位置的方法?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5926369/
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-08-23 19:32:25  来源:igfitidea点击:

Does Google Maps API offer a way to search for locations by name?

javascriptapisearchgoogle-mapsgeocoding

提问by dclowd9901

When one visits http://maps.google.com, they are able to type queries into the search field and receive results based on locations or places, and not hard search results, as they would in a normal Google Search query. They're a unique style of result (names of places, locations) suited to the Maps interface for obvious reasons.

当访问http://maps.google.com 时,他们能够在搜索字段中输入查询并接收基于位置或地点的结果,而不是像在普通 Google 搜索查询中那样的硬搜索结果。出于显而易见的原因,它们是适合地图界面的独特风格的结果(地名、位置)。

I've been digging through both the Maps and standard Google Search API for a couple hours now, and have done multiple searches on this question, and I can't seem to find the answer.

我已经在地图和标准 Google 搜索 API 上挖掘了几个小时,并且对这个问题进行了多次搜索,但似乎找不到答案。

They obviously have the Local Search, but that's been deprecated, and it only yields results if you provide an initial lat/long. I want to be able to find places or locations with no initial lat/long.

他们显然有本地搜索,但它已被弃用,并且只有在您提供初始纬度/经度时才会产生结果。我希望能够找到没有初始纬度/经度的地方或位置。

Essentially what I want to do is allow a user to type in an address, name of a place or name of a city or state or a zip code, or essentially any other kind of location that is allowable on Maps, and geocode it. I feel stupid because this seems like it has to be there, but nothing I've seen in the API seems to do this.

本质上,我想要做的是允许用户输入地址、地名或城市或州名或邮政编码,或者基本上是地图上允许的任何其他类型的位置,并对其进行地理编码。我觉得很愚蠢,因为这似乎必须存在,但我在 API 中看到的似乎没有做到这一点。

I don't need the AJAX suggested results, necessarily. Just a way for a user to type in a nice name and geocode from it, though results as a user types would be ideal.

我不一定需要 AJAX 建议的结果。只是用户输入一个好的名称和地理编码的一种方式,尽管用户输入的结果将是理想的。

What am I missing here?

我在这里缺少什么?

采纳答案by rbawaskar

What you are looking is Geocoding API from google maps.

您正在寻找的是来自谷歌地图的地理编码 API。

Find Documentation here

在此处查找文档

UPDATE 5/12/2011

更新 5/12/2011

Google just opened up public access to their Places API. This is more to the heart of the original question request:

谷歌刚刚开放了对其 Places API 的公开访问。这更符合原始问题请求的核心:

http://code.google.com/apis/maps/documentation/places/autocomplete.html

http://code.google.com/apis/maps/documentation/places/autocomplete.html

回答by mu is too short

I think you're looking for the google.maps.Geocoderclass:

我认为您正在寻找google.maps.Geocoder课程:

A service for converting between an address and a LatLng.

用于在地址和 LatLng 之间进行转换的服务。