使用 Google 地图提供简单的地址/行车路线
我一直在研究 Google Maps API 信息,但我似乎找不到一个例子,也找不到做我想做的事情的正确方法。
我需要从一个简单的 HTML 布局中显示一个 Google 地图,其中列出一个地址作为标记,用户可以单击“获取路线”或类似的内容来获取行车路线。
我有完整的地址,但没有纬度或经度信息。 有没有人有一个好的指导,或者一个可以分享的简单示例?
I have been pouring over the Google Maps API information, and for the life of me I can't seem to find an example, or figure out the exact right way of doing what I want.
From a simple HTML layout I need to display a Google Map, with a single address listed as a marker, with the user having the ability to click "Get Directions" or something similar to get driving directions.
I have a full address, but no Latitude or Longitude information. Does anyone have a good pointer, or a simple example of doing this that they could share?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要为此使用 API。 您可以将查询直接发送到 iframe 中的 Google 地图对象。
例如,显示白宫:
生成的地图有一个地址标记,允许用户获取方向。
You don't need to use the API for this. You can send a query directly to a Google maps object in an iframe.
For example, to show the White House:
The resulting map has a single address marker which allows the user to get directions.
您可以使用“地理编码器服务”获取任何地址的纬度和经度,有很多免费服务。 geocoder.us 是一项免费服务,您可以通过它对美国的任何地址进行“地理编码”。 另外,请访问网站 http://googlemapsbook.com/geocoders/ 了解更多此类地理编码器。 但是,我认为没有一种简单的方法来获取行车路线,据我所知 Google 地图 API 没有公开此类功能。
You can get the latitude and longitude of any address using "geocoder services" there are lots of services available for free. geocoder.us is a free service through which you can "geocode" any address in the USA. Also, look at the site http://googlemapsbook.com/geocoders/ to find out more such geocoders. However, I don't think there is an easy way to get the driving directions, As far as I know the Google Maps API doesn't expose such functionality.