简体   繁体   English

Google Maps Embed API Current Location 作为 iframe 的起点

[英]Google Maps Embed API Current Location as starting point with iframe

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我想要做的是将地址设置为目的地和起点(起点)我想放置设备的当前位置,但我找不到任何适用于 iframe 的在线内容,我发现的是将当前位置设为原点,但它似乎不起作用,我也尝试了我的位置、当前地址,因为我在意大利,所以我也尝试过使用意大利语,但还是一样,任何人都知道正确的命令是什么放置为原点,因此它会自动获取用户位置作为起点

 .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>

You can get the current position using Geolocation API and then use it in latitude,longitude format.您可以使用Geolocation API获取当前位置,然后以纬度、经度格式使用它。

For instance, it could look like https://www.google.com/maps/embed/v1/directions?origin=40.871579,14.2878583&destination=Rome例如,它可能看起来像https://www.google.com/maps/embed/v1/directions?origin=40.871579,14.2878583&destination=Rome

Try to use PlaceID in your destination so that Current Location will work in your origin.尝试在您的目的地使用 PlaceID,以便当前位置在您的原点工作。

<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罗马 PlaceID = ChIJu46S-ZZhLxMROG5lkwZ3D7k

Use this Place ID documentation to get the PlaceID of your destination.使用此 Place ID文档获取目的地的 PlaceID。

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.只需在您的 src URL 末尾添加这些参数之一,并使用您想要的纬度和经度。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM