0

I would like to plot markers on Google Maps for iOS, and this by including JSON file that will includes longitude and latitude. I can do it manually in the code, by replacing the values. The problem is that I don't know how to show new markers on the map from JSON file.

Here is my code :

- (void)addDefaultMarkers {
// Add a custom 'glow' marker around Sydney.
GMSMarker *sydneyMarker = [[GMSMarker alloc] init];
sydneyMarker.title = @"Sydney!";
sydneyMarker.icon = [UIImage imageNamed:@"glow-marker"];
sydneyMarker.position = CLLocationCoordinate2DMake(25.062718, 55.130761);
sydneyMarker.map = mapView_;
GMSMarker *melbourneMarker = [[GMSMarker alloc] init];
melbourneMarker.title = @"Melbourne!";
melbourneMarker.icon = [UIImage imageNamed:@"arrow"];
melbourneMarker.position = CLLocationCoordinate2DMake(25.100822, 55.17467);
melbourneMarker.map = mapView_;
}

Any ideas on how to do it ?

Al_fareS
  • 725
  • 1
  • 9
  • 18
  • chech my question in this link, http://stackoverflow.com/questions/20902732/how-to-plot-the-markers-in-google-maps-from-a-dictionay-in-ios. This link will help – chandru Jan 07 '14 at 14:01
  • I read your post, and it seems to me that I want to do the same idea a you, can you please tell me how I can parse the JSON data and collect it as dictionary ? A code snippet will be very helpful. – Al_fareS Jan 07 '14 at 15:59
  • For that U can study about web services, to request and get the data, then parse the data as U needed, using JSON parsing, into array or dictionay as ur wish, then U can plot those values in ur map, I will edit my answer and explain U, – chandru Jan 08 '14 at 08:30

1 Answers1

0

chech my question in this link, stackoverflow.com/questions/20902732/…. This link will help, First of all parse the json data. And collect it as array or dictionary, then U can directly plot the value in map
The first two lines are to parse the data into an array

SBJsonParser *jsonParser = [SBJsonParser new];    
NSArray *jsonData = (NSArray *) [jsonParser objectWithString:outputData error:nil];  

then, the loop should continue till the no. of values,

for(int i=0;i<[jsonData count];i++)
{
NSDictionary *dict=(NSDictionary *)[jsonData objectAtIndex:i];
Nslog(@"%@",dict);
double la=[[dict objectForKey:@"latitude"] doubleValue];
double lo=[[dict objectForKey:@"longitude"] doubleValue];

CLLocation * loca=[[CLLocation alloc]initWithLatitude:la longitude:lo];
CLLocationCoordinate2D coordi=loca.coordinate;

marker=[GMSMarker markerWithPosition:coordi];
marker.snippet = @"Hello World";
marker.animated = YES;
marker.map = mapView;
}  
Josh Crozier
  • 233,099
  • 56
  • 391
  • 304
chandru
  • 407
  • 1
  • 5
  • 26
  • It seems to be fine for me, the only thing that I have doubt on, is where to add the JSON file link ? So that I keep the latitude and longtitude value keep changing dynamically. – Al_fareS Jan 12 '14 at 08:56
  • for that U have to study about web services, check this link http://codewithchris.com/tutorial-how-to-use-ios-nsurlconnection-by-example/ – chandru Jan 13 '14 at 05:04
  • Thank, it is a very useful link ! just tell me please something, in your code how can I declare jsonData, SBJsonParser ? and when exactly should I put the code to be working perfectly ? – Al_fareS Jan 13 '14 at 20:41