Hi I am working on Google Maps SDK for ios. I want to plot a number of markers in Google maps from NSArray which contains location name, latitude and longitude. I tried using For loops which seems a little lame already but,
for(int i=0;i<=[myArray count];i++){
self.view = mapView_;
NSString *lat = [[myArray objectAtIndex:i] objectForKey:@"latitude"];
NSString *lon = [[myArray objectAtIndex:i] objectForKey:@"longitude"];
double lt=[lat doubleValue];
double ln=[lon doubleValue];
NSString *name = [[myArray objectAtIndex:i] objectForKey:@"name"];
NSLog(@"%@ and %@ and %f and %f of %@",lat,lon, lt,ln,name);
GMSMarker *marker = [[GMSMarker alloc] init];
marker.animated=YES;
marker.position = CLLocationCoordinate2DMake(lt,ln);
marker.title = name;
marker.snippet = @"Kathmandu";
marker.map = mapView_;
}
Here myarray is the array that has location name , latitude longitude in string format which I converted it to double. When I run this code Xcode shows me NSRangeException: index beyond bounds, which is probably because I am trying to use same object to display different indexes in same map. But at the same time, I couldnot think of any way to use GMSMarker as array. I could however plot multiple markers if I used different GMSMarker objects, but that doesnot solve my problem. I made another object like this, using two GMSMarker objects work to show two markers on the same map.
GMSMarker *marker1 = [[GMSMarker alloc] init];
marker1.animated=YES;
marker1.position = CLLocationCoordinate2DMake(lt,ln);
marker1.title = name;
marker1.snippet = @"Kathmandu";
marker1.map = mapView_;
Any help?
NSLog(@"%@ and %@ and %f and %f of %@",lat,lon, lt,ln,name);
it prints you out all the documents from your array? – Vame Jul 13 at 10:49NSDictionary *d = [myArray objectAtIndex:i]
before theNSString *lat =
and put a breakpoint to check where exactly it crashes. Also try to remove the marker code and leave only the loop to run alone. It could be very helpful if you paste the part you generate themyArray
data. – Vame Jul 13 at 11:31