javascript - Android Phonegap - 如何打开原生谷歌地图应用程序

标签 javascript android google-maps cordova geolocation

我正在使用 Phonegap 开发一个 Android 应用程序,但无法弄清楚如何打开本地 Google map 应用程序来显示方向。我通过插入 URL 打开 map 没有任何问题,但打开应用程序让我很难过。到目前为止,我只能在iOS平台上找到Phonegap相关的开发建议。

我已将 Google map 添加到白名单权限,在我的脚本标记中包含正确的 Cordova.js 文件和 google map 链接,在我的 AndroidManifest.xml 文件中具有正确的权限,包含 Cordova.jar 和 Google Map API我的构建路径,res目录下有Phonegap xml文件夹,我的assets/www目录下有js文件,libs目录下有jar文件。

我想要完成的事情:

    1. 点击链接后,打开原生谷歌地图应用程序。如果设备上未安装应用程序,请通知用户未安装 Google map ,必须安装。
      一个。我已经在检查网络连接并按照应有的方式进行处理。
    2. 谷歌地图打开显示从用户当前位置到点击链接位置的路线。

以下示例在我的 Android 设备上的运行与在 iOS 上的运行方式完全相同,但显然无法打开 Google map 应用程序的操作。

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

第二个示例通过包含结束位置添加到第一个示例,尽管我无法弄清楚如何插入当前位置。最重要的是,它仍然无法打开 Google map 应用程序。

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

在下面的第三个示例中,我能够在我的应用程序中显示 map 。它确实显示了正确的路线(从 A 点到 B 点的俯 View ),但再次没有打开实际的 Google Maps 应用程序。

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

如果有人对此有链接或任何想法,我将非常感谢您的帮助。除了“Hello World”应用程序,这是我的第一个移动应用程序。请让我知道我是否遗漏了任何内容,或者我只是做错了。如果需要任何其他信息,请告诉我。

提前感谢您的帮助。

最佳答案

使用地理:输入 uri。

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

用户可以选择打开其设备上安装的任何 map 应用程序。

关于javascript - Android Phonegap - 如何打开原生谷歌地图应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15745096/

相关文章:

javascript - 在显示图库图像时需要有关 Flickr/JSON/Javascript 问题的帮助

javascript - 使用 css 样式打印 div

javascript - Meteor 发布带有额外字段

android - "Cannot find DriveId. Are you authorized to view this file?": Even if EXISTING_FOLDER_ID is set manually

Android 应用程序在方向更改时使用设备区域设置而不是强制区域设置

java - 删除 map View 中除选定区域之外的所有其他区域

javascript - 什么是验证诸如 mm/yyyy 之类的日期格式的正则表达式?

java - 如何将 Android View 的原点移至其中心?

css - 想要在谷歌地图中有一个 float 窗口。像这样的 : Is there a name for this object?(包含链接/图像。)

ios - 如何在ios中使用谷歌地图而不是默认 map ?