問(wèn)題描述
我正在使用 Phonegap 開(kāi)發(fā)一個(gè) Android 應(yīng)用程序,但無(wú)法弄清楚如何打開(kāi)本地 Google 地圖應(yīng)用程序來(lái)顯示方向.我通過(guò)插入 URL 打開(kāi)地圖沒(méi)有任何問(wèn)題,但打開(kāi)應(yīng)用程序讓我很難過(guò).到目前為止,我只能在iOS平臺(tái)上找到Phonegap相關(guān)的開(kāi)發(fā)建議.
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 地圖添加到白名單權(quán)限,在我的腳本標(biāo)記中包含正確的 Cordova.js 文件和 google 地圖鏈接,在我的 AndroidManifest.xml 文件中具有正確的權(quán)限,包含 Cordova.jar 和 Google Map API我的構(gòu)建路徑,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. 點(diǎn)擊鏈接后,打開(kāi)原生谷歌地圖應(yīng)用程序.如果設(shè)備上未安裝應(yīng)用程序,請(qǐng)通知用戶未安裝 Google 地圖,必須安裝.
- 一個(gè).我已經(jīng)在檢查網(wǎng)絡(luò)連接并按照應(yīng)有的方式進(jìn)行處理.
-
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 設(shè)備上的運(yùn)行與在 iOS 上的運(yùn)行方式完全相同,但顯然無(wú)法打開(kāi) Google 地圖應(yīng)用程序的操作.
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>
第二個(gè)示例通過(guò)包含結(jié)束位置添加到第一個(gè)示例,盡管我無(wú)法弄清楚如何插入當(dāng)前位置.最重要的是,它仍然無(wú)法打開(kāi) Google 地圖應(yīng)用程序.
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;
}
在下面的第三個(gè)示例中,我能夠在我的應(yīng)用程序中顯示地圖.它確實(shí)顯示了正確的路線(從 A 點(diǎn)到 B 點(diǎn)的俯視圖),但再次沒(méi)有打開(kāi)實(shí)際的 Google Maps 應(yīng)用程序.
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);
}
});
}
如果有人對(duì)此有鏈接或任何想法,我將非常感謝您的幫助.除了Hello World"應(yīng)用程序,這是我的第一個(gè)移動(dòng)應(yīng)用程序.請(qǐng)讓我知道我是否遺漏了任何內(nèi)容,或者我只是做錯(cuò)了.如果需要任何其他信息,請(qǐng)告訴我.
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>
用戶可以選擇打開(kāi)其設(shè)備上安裝的任何地圖應(yīng)用程序.
and the user will get the choice of opening any of the mapping applications installed on their device.
這篇關(guān)于Android Phonegap - 如何打開(kāi)原生谷歌地圖應(yīng)用程序的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!