嵌入谷歌地图与路线之间的两个标志使用纬度和经度

embed google map with a route between two marks using latitude and longitude

本文关键字:标志 两个 经度 纬度 谷歌地图 之间      更新时间:2023-09-26

我知道如何创建一个链接到谷歌地图的2个标志之间的路线使用晚和长这样

<a href='https://maps.google.com?saddr=lat,lon&daddr=lat,lon'target='_blank'></a>

问题是如何嵌入这个地图使用这些坐标到我的网站作为一个iframe

使用嵌入API

从文档

https://www.google.com/maps/embed/v1/directions
?关键= YOUR_API_KEY
起源,= +挪威奥斯陆
挪威,目的地=屈膝旋转法+
,避免=收费公路|

需要以下URL参数:

origin定义显示方向的起始点。该值可以是地名、地址或地名ID。该字符串应该进行url转义,因此诸如"City Hall,New York,NY"之类的地址应该转换为City+Hall,New+York,NY。(Google Maps Embed API在转义空格时同时支持+和%20。)位置id应该以place_id:作为前缀。destination定义方向的终点。

例子:

origin=40.7127837,-74.0059413  (New York, NY)
destination=42.3600825,-71.05888 (Boston, MA)
iframe code:
<iframe width="600" height="450" frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/directions?origin=40.7127837,-74.0059413&destination=42.3600825,-71.05888&key=..." allowfullscreen></iframe>
工作示例