我正在使用Phonegap编写我的第一个应用程序,并在Android设备上进行测试。我相信我已经授予了适当的权限:
<uses-permission android:name="android.permission.INTERNET" />
但是地图没有显示出来。我正在尝试从网络服务获取纬度和经度,并使用这些数据在Google地图上放置一个标记。我认为问题实际上是因为无法访问互联网,因为如果我将其作为网站通过Visual Studio运行,服务会返回坐标并显示地图。但是,当应用程序被编译并且该网站在应用程序webview中运行时,坐标未返回,也没有显示地图。
我还添加了一个表格来显示返回的坐标,同样在浏览器中显示,但在运行的应用程序中为空白。有人知道为什么webview无法连接到互联网并返回所需的数据吗?我已经删除了网络服务的实际地址,但我知道它没有问题,因为它在浏览器中可以工作。
HTML页面:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=true"></script>
<link rel="stylesheet" type="text/css" href="css/index.css" />
</head>
<body>
<div class="app2">
<div id="map" style="width: 200px; height: 150px"></div>
<script type="text/javascript">
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", "http://www.xxxxxxxx.com/mobile/iphone/xml/postal.asp?postal=33173", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
var myOptions = {
zoom: 10,
mapTypeId: google.maps.MapTypeId.ROADMAP,
};
var map = new google.maps.Map(document.getElementById("map"), myOptions);
var lat = x[i].getElementsByTagName("latitude")[0].childNodes[0].nodeValue;
var long = x[i].getElementsByTagName("longitude")[0].childNodes[0].nodeValue;
var pos = new google.maps.LatLng(lat, long);
var infowindow = new google.maps.InfoWindow({
map: map,
position: pos,
content: "Postcode 33173(Lat:" + lat + ", Long:" + long + ")"
});
map.setCenter(pos);
</script>
<script></script>
</div>
</body>
</html>
清单:
<?xml version='1.0' encoding='utf-8'?>
<manifest android:hardwareAccelerated="true" android:versionCode="1" android:versionName="1.0.0" android:windowSoftInputMode="adjustPan" package="dig.phonegap.loa_app" 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.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />
<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.READ_PHONE_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
<uses-permission android:name="android.permission.READ_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_CONTACTS" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.BROADCAST_STICKY" />
<uses-sdk android:minSdkVersion="10" android:targetSdkVersion="18" />
<application android:allowBackup="false"
android:hardwareAccelerated="true"
android:icon="@drawable/icon"
android:label="@string/app_name">
<activity android:configChanges="orientation|keyboardHidden|keyboard|screenSize|locale"
android:label="@string/app_name"
android:name="HelloWorld"
android:theme="@android:style/Theme.Black.NoTitleBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>