Search code examples
asp.netgoogle-mapsgoogle-maps-api-3google-maps-urls

Google maps API directions service redirects to JSON info, but how do I get it to open map app in phone?


I'm new to Google Map API. The following javascript opens a new page with the JSON data. The google documentation gives the following URL example, (I added the window.open javascript part). But there isn't a complete example anywhere that I found.

I'm trying to open this from my asp.net website, into open the google maps app on a phone to the places indicated. Of course, the places will be put in programmically.

function myNavFunc4(){
window.open("https://maps.googleapis.com/maps/api/directions/json?origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK&key=My_KEY");
}

Solution

  • In order to launch Google Maps app from your website you can use the Google Maps URLs. This API was designed for this purpose.

    Instead of using Directions API web service endpoint in your script you should create a Google Maps URL for directions.

    E.g.

    function myNavFunc4(){
        window.open("https://www.google.com/maps/dir/?api=1&origin=Chicago,IL&destination=Los+Angeles,CA&waypoints=Joplin,MO|Oklahoma+City,OK");
    }
    

    For further details please have a look at Google Maps URLs documentation.

    Enjoy.