Android Phonegap - How to Open Native Google Maps Application(Android Phonegap - 如何打开原生谷歌地图应用程序)
问题描述
我正在使用 Phonegap 开发一个 Android 应用程序,但无法弄清楚如何打开本地 Google 地图应用程序来显示方向.我通过插入 URL 打开地图没有任何问题,但打开应用程序让我很难过.到目前为止,我只能在iOS平台上找到Phonegap相关的开发建议.
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.
我已将 Google 地图添加到白名单权限,在我的脚本标记中包含正确的 Cordova.js 文件和 google 地图链接,在我的 AndroidManifest.xml 文件中具有正确的权限,包含 Cordova.jar 和 Google Map API我的构建路径,res目录下有Phonegap xml文件夹,我的assets/www目录下有js文件,libs目录下有jar文件.
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. 点击链接后,打开原生谷歌地图应用程序.如果设备上未安装应用程序,请通知用户未安装 Google 地图,必须安装.
- 一个.我已经在检查网络连接并按照应有的方式进行处理.
-
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.
以下示例在我的 Android 设备上的运行与在 iOS 上的运行方式完全相同,但显然无法打开 Google 地图应用程序的操作.
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>
第二个示例通过包含结束位置添加到第一个示例,尽管我无法弄清楚如何插入当前位置.最重要的是,它仍然无法打开 Google 地图应用程序.
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;
}
在下面的第三个示例中,我能够在我的应用程序中显示地图.它确实显示了正确的路线(从 A 点到 B 点的俯视图),但再次没有打开实际的 Google Maps 应用程序.
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);
}
});
}
如果有人对此有链接或任何想法,我将非常感谢您的帮助.除了Hello World"应用程序,这是我的第一个移动应用程序.请让我知道我是否遗漏了任何内容,或者我只是做错了.如果需要任何其他信息,请告诉我.
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.
提前感谢您的帮助.
推荐答案
使用地理:输入 uri.
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 - 如何打开原生谷歌地图应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Android Phonegap - 如何打开原生谷歌地图应用程序
基础教程推荐
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01