Is there a way to invoke navigation from mobile browser?

后端 未结 3 1786
情歌与酒
情歌与酒 2021-01-30 15:13

I am developing a very small HTML5/javascript website to be openned by mobile browsers from devices like android / iphone. I am using geo location of HTML5 to get the current l

3条回答
  •  醉梦人生
    2021-01-30 15:24

    Since this question was first posted and answered, as of Oct. 2017, Google has developed an API called Maps URL.

    It is a universal, cross-platform URL for launching google maps.

    https://www.google.com/maps/dir/?api=1 is the endpoint for maps that could include navigation.

    You add the following parameters:

    • Origin: &origin=new+york
    • Destination: &destination=san+fransisco
    • Navigation: &dir_action=navigate

    If you leave out the origin, it will detect the location of the device, which is probably better for navigation anyway:

    https://www.google.com/maps/dir/?api=1&destination=san+fransisco&dir_action=navigate

    This will not immediately open navigation, but will take you to a google map, which will have the navigation icon on the page, and will give the user the option to use the app (or download it if they don't have it). This seems like a good solution. I just tested it in my browser, my Google Pixel, and my iPhone and it works the same on each mobile device.

    Check out the rest of the documentation for more useful features: https://developers.google.com/maps/documentation/urls/guide

提交回复
热议问题