Android Phonegap - 如何打开本机Google地图应用程序 [英] Android Phonegap - How to Open Native Google Maps Application

查看:119
本文介绍了Android Phonegap - 如何打开本机Google地图应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Phonegap开发Android应用程式,因此无法找出如何开启Google地图应用程式来显示路线。我没有任何问题,通过插入一个URL打开一个地图,但打开应用程序有我死了。到目前为止,我只能在iOS平台上找到Phonegap相关的开发建议。



我已将Google地图添加到白名单权限,包括正确的Cordova。 js文件和谷歌地图链接在我的脚本标记,在我的AndroidManifest.xml文件,包括Cordova.jar和Google Map API在我的构建路径中有正确的权限,在res目录中有Phonegap xml文件夹,在我的资产中的js文件/ www目录,libs目录中的jar文件。



我要完成的工作:


    1.点击链接后,打开原生的Google地图应用程序。如果应用程式未安装在装置上,请通知使用者Google地图尚未安装,必须安装。

      a。我已经检查网络连接和处理,因为它应该做。

    2. Google地图会打开,显示用户当前位置到所点击链接位置的路线。

以下示例在我的Android设备上与iOS上的设置完全相同,但显然不会打开Goog​​le Maps应用程序的操作。

 < a> href =http://maps.google.com/maps?q=TD Washington DC>< img src =img / ico_pin.png/>白宫< / a>< / a> 

第二个示例通过包括结束位置添加到第一个,虽然我不能out如何插入当前位置。最重要的是,它仍然无法打开Goog​​le地图应用程序。

 < a href =javascript:openMaps daddr = 1600 + Pennsylvania + Ave + NW + Washington + DC + 20500 + USA');>< img src =img / ico_pin.png/> White House< / a> 

function openMaps(querystring){
var maproot ='';
maproot ='http://maps.google.com/maps?saddr=Current+Location&';
window.location = maproot + querystring;
}

在下面的第三个例子中,应用。它显示正确的路线(从从A点到B点的俯视图),但是不会打开实际的Google地图应用程序。

 < a id =whDirectionshref =#mm_directionsonclick =getDirections()> 
< img src =img / ico_pin.png/>白宫< / a>

< div data-role =content>
< div class =ui-bar-c ui-corner-all ui-shadowstyle =padding:1em;>
< div id =mapdirections_canvasstyle =height:300px;>< / div>
< / div>
< / div>

function getDirections(){
var directionsService = new google.maps.DirectionsService();
var map;
var directionsDisplay = new google.maps.DirectionsRenderer();
var mapOptions = {
zoom:9,
zoomControl:true,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById(mapdirections_canvas),mapOptions);
directionsDisplay.setMap(map);

var myLatLng = new google.maps.LatLng(gmmLat,gmmLong);
if(document.getElementById(whDirections)){
var request = {
origin:myLatLng,
destination:new google.maps.LatLng(38.897096,-77.036545) ,
travelMode:google.maps.TravelMode.DRIVING
};
directionsService.route(request,function(result,status){
if(status == google.maps.DirectionsStatus.OK){
directionsDisplay.setDirections(result);
}
});
}

如果任何人有链接或任何想法,帮帮我。除了Hello World应用程序,这是我的第一个移动应用程序。请让我知道,如果我错过了任何东西,或者我只是做这个完全错了。



感谢您提供帮助。

如果您需要任何其他信息,请告诉我们。解决方案

使用geo:type uri。

 < a href =geo:38.897096, -77.036545>打开地图< / a> 

,用户将可以选择打开他们设备上安装的任何地图应用程序。 p>

I'm working on an Android application using Phonegap and am having trouble figuring out how to open the native Google Maps application to display directions. I don't have any issue opening a map by inserting a URL but opening the application has me stumped. So far I have only been able to find Phonegap related suggestions for development on the iOS platform.

I have added Google Maps to the whitelist permissions, am including the correct Cordova.js file and google maps link in my script tag, have the correct permissions in my AndroidManifest.xml file, included Cordova.jar and Google Map API in my build path, have the Phonegap xml folder in the res directory, js file in my assets/www directory, jar file in the libs directory.

What I am trying to accomplish:

    1. When a link is clicked, open the native Google Maps application. If the application is not installed on the device, notify the user that Google Maps is not installed and must be installed.
      a. I am already checking for network connectivity and handling that as it should be done.
    2. Google Maps opens displaying directions from the user's current location to the location of the link clicked.

The example below works on my Android device exactly the same as it does on iOS but obviously does not open the actions Google Maps application.

<a> href="http://maps.google.com/maps?q=TD Washington DC"><img src="img/ico_pin.png" />White House</a></a>

The second example adds on to the first by including the end location although I wasn't able to figure out how to insert the current location. Most importantly though, it still doesn't open the Google Maps application.

<a href="javascript:openMaps('daddr=1600+Pennsylvania+Ave+NW+Washington+DC+20500+USA');"><img src="img/ico_pin.png" />White House</a>

function openMaps(querystring) {
    var maproot = '';
    maproot = 'http://maps.google.com/maps?saddr=Current+Location&';
    window.location = maproot + querystring;
}

In the third example below, I'm able to display a map within my application. It does show the correct route (from an overhead view from point A to point B) but again doesn't open the actual Google Maps application.

<a id="whDirections" href="#mm_directions" onclick="getDirections()">
                    <img src="img/ico_pin.png" />White House</a>

<div data-role="content">
    <div class="ui-bar-c ui-corner-all ui-shadow" style="padding: 1em;">
        <div id="mapdirections_canvas" style="height: 300px;"></div>
    </div>
</div>

function getDirections() {
    var directionsService = new google.maps.DirectionsService();
    var map;
    var directionsDisplay = new google.maps.DirectionsRenderer();
    var mapOptions = {
        zoom: 9,
        zoomControl: true,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };
    var map = new google.maps.Map(document.getElementById("mapdirections_canvas"), mapOptions);
    directionsDisplay.setMap(map);

    var myLatLng = new google.maps.LatLng(gmmLat, gmmLong);
    if (document.getElementById("whDirections")) {
        var request = {
            origin: myLatLng,
        destination: new google.maps.LatLng(38.897096, -77.036545), 
            travelMode: google.maps.TravelMode.DRIVING
    };
    directionsService.route(request, function(result, status) {
        if (status == google.maps.DirectionsStatus.OK) {
            directionsDisplay.setDirections(result); 
        }
    });
}

If anyone has a link or any idea on this, I would really appreciate the help. Other than a 'Hello World' app, this is my first mobile application. Please let me know if I have missed anything or if I am just doing this completely wrong. If any additional information is needed, please let me know.

Thanks in advance for the help.

解决方案

Use the geo: type uri.

<a href="geo:38.897096,-77.036545">open map</a>

and the user will get the choice of opening any of the mapping applications installed on their device.

这篇关于Android Phonegap - 如何打开本机Google地图应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆