I am using HTML5 template in appcelerator studio and developing iPhone app application.i have one html file(map.html)and it has one coordinates() function which i have defined in locationCoordinates.js file. This .js file is located inside ui folder. In coordinates() function i have calling this function Titanium.Network.createHTTPClient(); and url but it is not working.how to fire xhr.onload() function.please let me know how can i solve this issue here is my code:
map.html <!DOCTYPE html> <html> <head> <meta name="viewport" content="initial-scale=1.0, user-scalable=no"> <meta charset="utf-8"> <title>Custom Marker Symbols</title> <style> html, body, #map-canvas { height: 100%; margin: 0px; padding: 0px } </style> <script src="../ui/locationCoordinates.js"></script> <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false"></script> <script> function initialize() { var x= coordinates(); var pyrmont = new google.maps.LatLng(-37.681502,145.019120); var mapOptions = { zoom: 8, center: pyrmont, mapTypeId: google.maps.MapTypeId.ROADMAP };
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
var goldStar = { path: 'M 0,-24 6,-7 24,-7 10,4 15,21 0,11 -15,21 -10,4 -24,-7 -6,-7 z', fillColor: 'yellow', fillOpacity: 0.4, scale: 1, strokeColor: 'gold', strokeWeight: 3 };
var marker = new google.maps.Marker({ position: map.getCenter(), icon: goldStar, map: map });
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head> <body> <div id="map-canvas"></div> </body> </html>
locationCoordinates.js file code
function coordinates(){
var url="http://ems02.bksv.com/WebTrak/mel3/configuration"; // rss feed url var xhr = Titanium.Network.createHTTPClient();
xhr.onload = function() {
var doc = this.responseXML.documentElement;
// begin looping through blog posts
var items = doc.getElementsByTagName("nmts");
var level = items.item(0).getElementsByTagName("locations");
var completeloc;
for(var x=0; x<level.length;x++)
{
var lat= level.item(x).getAttribute("latitude");
var lon= level.item(x).getAttribute("longitude");
}
alert(lat);
}; // end function() xhr.onerror = function(e) { // should do something more robust alert('Network error '+e.error); };
xhr.open('GET',url); xhr.send();
return lat; }