How to create a link for all mobile devices that opens google maps with a route starting at the current location, destinating a given place?

前端 未结 10 555
无人及你
无人及你 2021-01-29 17:33

I rather thought this would not be so hard to find out but appearantly it is not easy to find an awesome cross device article, like you\'d expect.

I want to create a lin

相关标签:
10条回答
  • 2021-01-29 18:15

    I found that this works across the board:

    <a href="https://www.google.com/maps/place/1+Fake+Street,+City+Province/State>Get Directions</a>

    For desktops/laptops the user has to click Directions when that map loads, but from my testing all mobile devices will load that link in the Google Maps app without difficulty.

    0 讨论(0)
  • 2021-01-29 18:17

    Simple URL :

    https://www.google.com/maps/dir/?api=1&destination=lat,lng
    

    This url is specific for routing.

    Reference : https://developers.google.com/maps/documentation/urls/guide#directions-action

    0 讨论(0)
  • 2021-01-29 18:17

    Based on the documentation the origin parameter is optional and it defaults to the user's location.

    ... Defaults to most relevant starting location, such as user location, if available. If none, the resulting map may provide a blank form to allow a user to enter the origin....

    ex: https://www.google.com/maps/dir/?api=1&destination=Pike+Place+Market+Seattle+WA&travelmode=bicycling

    For me this works on Desktop, IOS and Android.

    0 讨论(0)
  • 2021-01-29 18:19

    The URL syntax is the same regardless of the platform in use

    String url = "https://www.google.com/maps/search/?api=1&query=" + latitude + ","+ 
    longitude;
    

    In Android or iOS the URL launches Google Maps in the Maps app, If the Google Maps app is not installed, the URL launches Google Maps in a browser and performs the requested action.

    On any other device, the URL launches Google Maps in a browser and performs the requested action.

    here's the link for official documentation https://developers.google.com/maps/documentation/urls/guide

    0 讨论(0)
  • 2021-01-29 18:23

    Well no, from an iOS developer prospective, there are two links that I know of that will open the Maps app on the iPhone

    On iOS 5 and lower: http://maps.apple.com?q=xxxx

    On iOS 6 and up: http://maps.google.com?q=xxxx

    And that's only on Safari. Chrome will direct you to Google Maps webpage.

    Other than that you'll need to use a URL scheme that basically beats the purpose because no android will know that protocol.

    You might want to know, Why Safari opens the Maps app and Chrome directs me to a webpage?

    Well, because safari is the build in browser made by apple and can detect the URL above. Chrome is "just another app" and must comply to the iOS Ecosystem. Therefor the only way for it to communicate with other apps is by using URL schemes.

    0 讨论(0)
  • 2021-01-29 18:25

    This works for me on all devices [ iOS, Android and Window Mobile 8.1 ].

    Does not look like the best way by any means... but cannot be more simpler :)

    <a href="bingmaps:?cp=18.551464~73.951399">
     <a href="http://maps.apple.com/maps?q=18.551464, 73.951399"> 
       Open Maps
     </a>
    </a>
    

    http://jsbin.com/dibeq

    0 讨论(0)
提交回复
热议问题