|
0
|
I am trying to add locations to a map using JSON and I need some help. I'm using SumitK's example to pull in a Drupal JSON service for tableViews. I'm trying to modify it for map annotations but am having issues. Below is what I have so far. Could anyone give me some pointers? var url = 'http://localhost:8888/class-services/services/json'; var win = Titanium.UI.currentWindow; win.backgroundColor = '#dce0e4'; var data = []; var view = new Object; view.method = 'views.get'; view.view_name = 'autos'; var xhr = Titanium.Network.createHTTPClient(); xhr.open("POST",url); xhr.send({data: JSON.stringify(view)}); xhr.onload = function() { Ti.API.info(this.responseText); var data = JSON.parse(this.responseText); Ti.API.info(data); for (var c=0;c<data.length;c++) { var mountainView = Titanium.Map.createAnnotation({ latitude:data[c]['lat'], longitude:data[c]['long'], title:data[c]['title'], subtitle:data[c]['street_address'], pincolor:Titanium.Map.ANNOTATION_RED, animate:true, leftButton: 'images/appcelerator_small.png', myid:1 }); } } var lat = ''; var lon = ''; Titanium.Geolocation.getCurrentPosition(function(e) { lat = e.coords.latitude; lon = e.coords.longitude; var mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, region: {latitude:lat, longitude:lon, latitudeDelta:0.01, longitudeDelta:0.01}, animate:true, regionFit:true, userLocation:true, annotations:[mountainView] }); // add table view to the window Titanium.UI.currentWindow.add(mapview); }); asked 2 months ago
|
|
0
|
I feel like an idiot! Its mapview.setAnnotations not mapview.addAnnotation. I kept going over the code and wondering why only 1 location was being added. Below is the section of code for adding the points. Thanks for all the feedback. mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, animate:true, userLocation:true, region: {latitude:lat, longitude:lng, latitudeDelta:0.01, longitudeDelta:0.01}, regionFit:true }); mapview.setAnnotations(points); var points = []; for (var c=0; c<data.length; c++) { points[c] = Titanium.Map.createAnnotation({ latitude:data[c].lat, longitude:data[c].lng, title:data[c].title, subtitle:data[c].subtitle, pincolor:Titanium.Map.ANNOTATION_PURPLE, animate:true, myid:c }); } answered 3 weeks ago
|
|
0
|
Joe - can you share the full code of your working example? I can't get mapview.addAnnotation to work in my for loop. I'd like to look at your code and see what I am doing wrong. answered 3 weeks ago
|
|
0
|
This works for me: var win = null; var pin = []; win = Titanium.UI.createWindow({ backButtonTitle:'Back', title:'Title', tabBarHidden:true }); mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, animate:true, userLocation:true, region: {latitude:lat, longitude:lng, latitudeDelta:0.01, longitudeDelta:0.01}, regionFit:true }); for (var i=0; i<data.length; i++) { pin[i] = Titanium.Map.createAnnotation({ latitude:data[i].lat, longitude:data[i].lng, title:data[i].title, subtitle:data[i].subtitle, pincolor:Titanium.Map.ANNOTATION_PURPLE, animate:true, myid:i }); mapview.addAnnotation(pin[i]); } win.add(mapview); Titanium.UI.currentTab.open(win,{animated:true}); answered 4 weeks ago
by Joe Maffia
|
|
0
|
Got it working except its only displaying 1 location. The code is below, can anyone see what I'm doing wrong? var lat = ''; var lon = ''; var url = 'http://localhost:8888/class-services/services/json'; var data = []; var view = new Object; view.method = 'views.get'; //view.hash = hash; //view.domain_name = domain; //view.domain_time_stamp = timestamp; //view.nonce = nonce; view.view_name = 'yardsales'; var xhr = Titanium.Network.createHTTPClient(); xhr.open("POST",url); xhr.send({data: JSON.stringify(view)}); xhr.onload = function() { Ti.API.info(this.responseText); var data = JSON.parse(this.responseText); Ti.API.info(data); for (var c=0;c<data.length;c++) { data = Titanium.Map.createAnnotation({ latitude:data[c]['locations'][0]['latitude'], longitude:data[c]['locations'][0]['longitude'], title:data[c]['locations'][0]['street'], subtitle:data[c]['field_date'][0]['value']+': Starting at '+data[c]['field_stime'][0]['value'], pincolor:Titanium.Map.ANNOTATION_RED, animate:true, rightButton: Titanium.UI.iPhone.SystemButton.DISCLOSURE, myid:(c+1) }); Titanium.Geolocation.getCurrentPosition(function(e) { lat = e.coords.latitude; lon = e.coords.longitude; var mapview = Titanium.Map.createView({ mapType: Titanium.Map.STANDARD_TYPE, region: {latitude:lat, longitude:lon, latitudeDelta:0.01, longitudeDelta:0.01}, animate:true, regionFit:true, userLocation:true, annotations:[data] }); Titanium.UI.currentWindow.add(mapview); }); } }; answered 6 weeks ago
|
|
0
|
I've been working on this today and have gotten it to work, sort of. All the JSON data gets placed in the same pin instead of multiple pins being dropped. Once I get it fully working, I'll share the code. answered 6 weeks ago
|
|
0
|
May also be worth asking this question in the Drupal Titanium group recently setup http://groups.drupal.org/titanium-api Sorry I have not yet tried this so can't offer assistance yet answered 2 months ago
by Gregg Coppen
|
*italic* / _italic_**bold** / __bold__Header 1
========Header 2
--------### Header 3#### Header 4An [inline](http://href.com) linkReference [links][id] are defined via ids added somewhere else.
[id]: http://href.com1. Ordered
2. Lists- Unordered
- Lists`inline code` (backticks)~~~
code block (three tildes)
~~~> Paragraph.