mobile html5 launch phone's native navigation app

前端 未结 5 1075
灰色年华
灰色年华 2021-02-01 07:30

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 applic

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-01 07:50

    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:

    1. Open a console window
    2. Go to your Phonegap app root
    3. Then execute: phonegap local plugin add https://github.com/viktor0710/PhoneNavigator-Phonegap-3.x.git
    4. Copy "phonenavigator.js" from the repo (www/phonenavigator.js) in your app (ex: yourapp/www)
    5. include "phonenavigator.js" in you app:
    6. Copy "cordova.js" from the repo (www/cordova.js) in your app (ex: yourapp/www)
    7. include "cordova.js" in you app:

    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");
        }
    );
    

提交回复
热议问题