3

What i'm trying to do is set an address as destination and as the origin (starting point) I would like to put the current location of the device, but i cannot find anything on line that works with the iframe, all i found is to key current location as origin, but it doesn't seem to work, i also tried my location, current address and as i'm in italy i also tried with italian language, but all the same, any one know what's the correct command to put as origin so it will automatically get the user location as starting point

.maps {
  width: 600px;
  height: 200px;
  border: 0;
}
<iframe allowfullscreen="" class="maps" frameborder="0" id="mapnavi" name="mapnavi" src="https://www.google.com/maps/embed/v1/directions?
origin=current+location
&destination=rome
&key=AIzaSyC-5CY9mOCeg5Y3IhPqi_Yd0-DZtWrJl-E">
</iframe>
Benedetto
  • 71
  • 1
  • 2
  • 10

3 Answers3

2

You can get the current position using Geolocation API and then use it in latitude,longitude format.

For instance, it could look like https://www.google.com/maps/embed/v1/directions?origin=40.871579,14.2878583&destination=Rome

Anatolii Suhanov
  • 2,524
  • 1
  • 12
  • 14
  • 1
    yes, i just found out from google support that this cannot be done with i frame |Google Maps Embed API| and they are not planning to add this feature, must use JavaScript Maps API – Benedetto Oct 06 '16 at 08:29
  • Well in any case whether it's Javascript or Ember API you need a way to detect the current location and send it as a parameter. Neither of the APIs will understand anything like "current position", "my location" or "current address", because those values do not make any sense for a remote web server. See https://developers.google.com/web/fundamentals/native-hardware/user-location/?hl=en – Anatolii Suhanov Oct 06 '16 at 09:41
-1

Try to use PlaceID in your destination so that Current Location will work in your origin.

<iframe width="500" height="500" 
frameborder="0" style="border:0" src="https://www.google.com/maps/embed/v1/directions?
origin=Current%20Location&destination=place_id:ChIJu46S-ZZhLxMROG5lkwZ3D7k&key=YOUR_API_KEY"
allowfullscreen></iframe>

Rome PlaceID = ChIJu46S-ZZhLxMROG5lkwZ3D7k

Use this Place ID documentation to get the PlaceID of your destination.

KENdi
  • 7,576
  • 2
  • 16
  • 31
  • 1
    No, I was told by Google support, that currently this feature is not supported, and they are not planning to. Must use JavaScript Maps API – Benedetto Oct 09 '16 at 01:56
-1

One of those three parameters should work:

  1. &origin=lat,lang
  2. &center=lat,lang
  3. &ll=lat,lang

Just add one of these parameters at the end of your src URL with your desired latitude & longitude.

Mimina
  • 2,603
  • 2
  • 29
  • 21