Drupal + Titanium Map + Location Module

ok so you are using drupal web services with a node with the location (cck) field and you want to plot that on the map in your mobile application :) well my friend here is an example of that: and you are using json response formatters: in your titanium app.j:

var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundColor:'#fff'
});


//network ip 
var theurl = 'http://192.168.1.9.999/yourdrupal/endpoint/node/123';
 
var xhr = Ti.Network.createHTTPClient({
onload: function(e) {
//Ti.API.debug(this.responseText);
    
//alert(this.responseText);
    
var json = JSON.parse(this.responseText);
var nodetitle = json.title;
var body = json.body.und[0].value;
var thenid = json.nid;
//change to the field location cck name var nodelatitude = json.field_loc_location.und[0].latitude; var nodelongitude = json.field_loc_location.und[0].longitude; // annotation prob put in a foreach later on :) var annotation = Titanium.Map.createAnnotation({ latitude:nodelatitude, longitude:nodelongitude, title:nodetitle, subtitle:body, image:"pin.png",//The center of the pin will register on the latitude and longitude animate:true }); var mapView = Titanium.Map.createView({ top:0, left:0, height:"100%", width:"100%", mapType: Titanium.Map.STANDARD_TYPE, //Selections for the above include: //Titanium.Map.STANDARD_TYPE //Titanium.Map.SATELLITE_TYPE //Titanium.Map.HYBRID_TYPE region: { latitude:-50.091282678529513, //GPS coordinates to center the map around longitude:15.40621948242188, //GPS coordinates to center the map around latitudeDelta:4, //Think of this like x-zoom longitudeDelta:4 //This of this like y-zoom }, animate:true, //Animate the map towards the region regionFit:false, //Attempt to fit the specified region within the visible area userLocation:true, //Will show a blue dot at your current location annotations:[annotation]//The annotations property of the map view expects an array of annotation objects }); win1.add(mapView); //add some thing to the click mapView.addEventListener("click",function(e){ if(e.clicksource === "title"){ alert('do someing with the nodeid' + thenid); } }); }, onerror: function(e) { Ti.API.debug(e.error); alert('error'); }, timeout:5500 }); xhr.open("GET", theurl); xhr.send();
Category: