Monday, 26 August 2013

phonegap android internet not working

phonegap android internet not working

I am writing my first app in phonegap and have been testing it on an
android device. I believe I have granted the appropriate permission:
<uses-permission android:name="android.permission.INTERNET" />
But the map is not showing up. I am trying to get a latitude and longitude
from a web service and use this to put a flag on a google map. I believe
the issue is actually with the internet access as if I run this through
visual studio as a website the service returns the co-ordinates and the
map is displayed. However, when the app is compiled and that website is
run inside the app webview the co-ordinates are not returned and no map is
displayed. I also added a table to show the returned co-ordinates, again
they are displayed in a browser but are blank in the running app. Anyone
have any idea why the webview wouldn't be able to connect to the internet
and return the required data? I have removed the actual address of the web
service but I know that is fine as it works in a browser.
<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>
document.write("<table border='1'>");
document.write("<tr><td>Postcode</td><td>latitude</td><td>longitude</td></tr>");
var x = xmlDoc.getElementsByTagName("position");
for (i = 0; i < x.length; i++) {
document.write("<tr><td>33173</td><td>");
document.write(x[i].getElementsByTagName("latitude")[0].childNodes[0].nodeValue);
document.write("</td><td>");
document.write(x[i].getElementsByTagName("longitude")[0].childNodes[0].nodeValue);
document.write("</td></tr>");
}
document.write("</table>");
</script>
</div>

No comments:

Post a Comment