How can I display multiple markers on the Google Map in iOS? I used the following approach, but it didn't work.
for (int i = 0; i < [array count]; i++)
{
pointsToUse[i] = CLLocationCoordinate2DMake([[[[array objectAtIndex:0] componentsSeparatedByString:@","] objectAtIndex:0] floatValue],[[[[array objectAtIndex:0] componentsSeparatedByString:@","] objectAtIndex:1] floatValue]);
[_map animateToLocation:pointsToUse[i]];
GMSMarkerOptions *options = [[GMSMarkerOptions alloc] init];
options.position = pointsToUse[i];
[_map animateToLocation:pointsToUse[i]];
[_map addMarkerWithOptions:options];
}
I tried your code. This seems to work fine. Just delete the object at index 0 after passing it values to pointsToUse.
Yes both of you are correct. According to your suggestions I changed the code and it works. But the problem is, I set the zoom and the zoom is fixed. If the two locations are far, I can't see both locations on one screen ( i need to pinch to see both). How can I see both locations at the same time? My code is shown below.
You're using
[array objectAtIndex:0]
(in two places), when I think you should probably be using[array objectAtIndex:i]
?Also, you probably don't need the calls to
animateToLocation
?Try this: