admin管理员组

文章数量:1418343

I know how to create a link to google maps with a route between 2 marks using lat and long like this

<a href=',lon&daddr=lat,lon'target='_blank'></a>

The question is how to embed this map using these coordinates into my website as an iframe

I know how to create a link to google maps with a route between 2 marks using lat and long like this

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

The question is how to embed this map using these coordinates into my website as an iframe

Share Improve this question asked Oct 14, 2015 at 19:04 PHP UserPHP User 2,4226 gold badges52 silver badges99 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Use the Embed API

from the documentation

https://www.google./maps/embed/v1/directions
?key=YOUR_API_KEY
&origin=Oslo+Norway
&destination=Telemark+Norway
&avoid=tolls|highways

The following URL parameters are required:

origin defines the starting point from which to display directions. The value can be either a place name, address or place ID. The string should be URL-escaped, so an address such as "City Hall, New York, NY" should be converted to City+Hall,New+York,NY. (The Google Maps Embed API supports both + and %20 when escaping spaces.) Place IDs should be prefixed with place_id:. destination defines the end point of the directions.

example:

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./maps/embed/v1/directions?origin=40.7127837,-74.0059413&destination=42.3600825,-71.05888&key=..." allowfullscreen></iframe>

working example

本文标签: javascriptembed google map with a route between two marks using latitude and longitudeStack Overflow