2015-05-26 59 views
0

我建立使用PhoneGap的和谷歌地圖API的應用程序無法地理位置在Android,但我發現我無法修復的問題:如果我測試應用在筆記本電腦上的瀏覽器(Chrome和Firefox測試)該應用程序完全正常工作!否則當我爲我的智能手機(OnePlus One)構建應用程序時,地圖未顯示,並且始終該方法調用失敗功能。谷歌地圖API使用PhoneGap的

這種情況與我的自定義代碼,並建立在谷歌API和jQuery移動網站的例子功能。

這裏說瀏覽器的工作原理教程代碼,它總是啓動失敗功能無法在設備上

$(document).on("pageinit", "#map-page", function() { 
var defaultLatLng = new google.maps.LatLng(34.0983425, -118.3267434); // Default to Hollywood, CA when no geolocation support 
if (navigator.geolocation) { 
    function success(pos) { 
     // Location found, show map with these coordinates 
     drawMap(new google.maps.LatLng(pos.coords.latitude, pos.coords.longitude)); 
    } 
    function fail(error) { 
     drawMap(defaultLatLng); // Failed to find location, show default map 
    } 
    // Find the users current position. Cache the location for 5 minutes, timeout after 6 seconds 
    navigator.geolocation.getCurrentPosition(success, fail, {maximumAge: 500000, enableHighAccuracy:true, timeout: 6000}); 
} else { 
    drawMap(defaultLatLng); // No geolocation support, show default map 
} 
function drawMap(latlng) { 
    var myOptions = { 
     zoom: 10, 
     center: latlng, 
     mapTypeId: google.maps.MapTypeId.ROADMAP 
    }; 
    var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions); 
    // Add an overlay to the map of current lat/lng 
    var marker = new google.maps.Marker({ 
     position: latlng, 
     map: map, 
     title: "Greetings!" 
    }); 
} 
}); 

我真的不明白,爲什麼在瀏覽器的工作原理,而不是設備。

編輯

新增Android清單

<?xml version='1.0' encoding='utf-8'?> 
<manifest android:hardwareAccelerated="true" android:versionCode="10000"  android:versionName="1.0.0" package="com.coolappz.TrovaOfficine" xmlns:android="http://schemas.android.com/apk/res/android"> 
<supports-screens android:anyDensity="true" android:largeScreens="true" android:normalScreens="true" android:resizeable="true" android:smallScreens="true" android:xlargeScreens="true" /> 
<uses-permission android:name="android.permission.INTERNET" /> 
<application android:hardwareAccelerated="true" android:icon="@drawable/icon" android:label="@string/app_name"> 
    <activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale" android:label="@string/activity_name" android:launchMode="singleTop" android:name="CordovaApp" android:theme="@android:style/Theme.Black.NoTitleBar" android:windowSoftInputMode="adjustResize"> 
     <intent-filter android:label="@string/launcher_name"> 
      <action android:name="android.intent.action.MAIN" /> 
      <category android:name="android.intent.category.LAUNCHER" /> 
     </intent-filter> 
    </activity> 
</application> 
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="21" /> 
<uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> 
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> 
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> 
<uses-permission   android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /> 
<uses-permission android:name="android.permission.VIBRATE" /> 
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> 
<uses-permission android:name="android.permission.RECORD_AUDIO" /> 
<uses-permission android:name="android.permission.RECORD_VIDEO" /> 
<uses-permission android:name="android.permission.READ_CONTACTS" /> 
<uses-permission android:name="android.permission.WRITE_CONTACTS" /> 
<uses-permission android:name="android.permission.GET_ACCOUNTS" /> 
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" /> 
<uses-permission android:name="android.permission.READ_PHONE_STATE" /> 
</manifest> 

最後更新

的問題已得到修復自己:d 我的意思是:我卸載從設備的應用程序,重新啓動手機,從項目中刪除未使用的插件,然後在新的構建和安裝一切工作正常。 我想這是一個插件問題。

+0

是否安裝了地理位置插件? 'cordova plugin add org.apache.cordova.geolocation'請參閱:http://docs.phonegap.com/en/edge/cordova_geolocation_geolocation.md.html瞭解更多信息。 – laughingpine

回答

0

你打開手機的地理位置?像GPS或什麼的?

因爲我有類似的經歷,這是因爲我的Nexus 7不具備GPS功能。在我而言有點兒傻..

+0

感謝您的回答,是的,我檢查了它與地理位置ON tryed和OFF太多,但仍然沒有工作 –

+0

嗯,你可以發表你的表現?您是否授予該應用程序的許可? –

+0

增加對答案 –