mobile html5 launch phone's native navigation app
I'm developing a phonegap/cordova app. Is there a way to open a phone's native navigation app within the browser view? Or is there a best practice on opening native map applications from html5 apps? Or are they all platform specific?
I've read some places that the following works for certain versions of Android
<a href="geo:some address here" />Navigate to here</a>
and that this works for iOS
<a href="http://maps.apple.com/?daddr=San+Francisco,+CA&saddr=cupertino">Directions</a>
I'm amazed that Phonegap hasn't implemented something like this.
You can open the native navigation app on iOS 5 (Google Maps) and iOS 6 (Apple Maps) by using the magic "maps:" protocol, eg window.location = "maps:daddr=50.4,-4.5"
But to launch the native Google Navigator app on Android you need to use a phonegap plugin. I wrote this one for my own purposes.
Update The plugin has now been updated for Phonegap 3.x and supports Android, iOS and Windows Phone, including an option to prefer Google Maps on iOS.
The plugin is here: https://github.com/dpa99c/phonegap-launch-navigator
The plugin is great! Thanks for sharing! I tried it in my app but unfortunately I have Phonegap version 3.x and your plugin is only working for Phonegap 2.x :(
So in order to get it working on Phonegap 3.x I got the plugin from your github repo and made some changes so that it works for 3.x
The modified PhoneNavigator Plugin for Phonegap 3.x can be downloaded from my github repo: https://github.com/viktor0710/PhoneNavigator-Phonegap-3.x.git
How to integrate it in your Phonegap 3.x project:
How to use it:
//function declaration
function navigateTo (lat, lon, successFn, errorFn) {
cordova.require('cordova/plugin/phonenavigator').doNavigate(lat, lon, successFn, errorFn);
}
//set lat and lon variables. Most probably read them from the UI
var latitude = 48.137607;
var longitude = 11.568569;
//call function
navigateTo(
latitude,
longitude,
function(){
console.log("Successfully opened navigator");
},
function(){
console.log("Error opening navigator");
}
);
As mentioned above, the following works on Galaxy S4 Android (just tested it), to bring up the Google Maps/Navigation app and waze:
<a href="geo:37.786971,-122.399677;u=35">Wikimedia Headquarters</a>
Credit: http://en.wikipedia.org/wiki/Geo_URI#Example
Please also see the answer here: https://stackoverflow.com/a/19765368/2728686
链接地址: http://www.djcxy.com/p/66554.html上一篇: 将基于html5 / css3 / js的电子书包装到android / iOS应用程序(无epub)
下一篇: 移动html5启动手机的原生导航应用程序