【发布时间】:2018-10-05 12:21:31
【问题描述】:
我想在谷歌地图上显示多个标记。有基于此的答案。但是地图上没有显示标记。虽然我根据数组结果获取纬度和经度值。我该怎么办?
注意:我做了一些改动,代码运行完美。
我的代码是:
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
[self performRequestForRestaurantListing];
geometryDict=[[NSMutableDictionary alloc]init];
locationDict=[[NSMutableDictionary alloc]init];
NSLog(@"the value of list is %@", _service);
NSLog(@"the value of stringradius is %@", _stringRadius);
/*---location Manager Initialize-------*/
self.manager=[[CLLocationManager alloc]init];
self.manager.distanceFilter = 100;
self.manager.desiredAccuracy = kCLLocationAccuracyBest;
[self.manager requestAlwaysAuthorization];
self.manager.delegate=self;
[self.manager startUpdatingLocation];
[mapView setDelegate:self];
latitude=@"22.5726";
longitude=@"88.3639";
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:[latitude doubleValue]
longitude:[longitude doubleValue]
zoom:12];
[mapView animateToCameraPosition:camera];
[self coordinateOnMap:latitude andWithLongitude:longitude];
}
-(void)coordinateOnMap:(NSString*)latitude andWithLongitude:(NSString*)longitude
{
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] init];
CLLocationCoordinate2D location;
for (int i=0;i<[restaurantList count];i++)
{
driverMarker = [[GMSMarker alloc] init];
latitude=[[[[restaurantList objectAtIndex:i]objectForKey:@"geometry"]objectForKey:@"location"] objectForKey:@"lat"];
longitude=[[[[restaurantList objectAtIndex:i]objectForKey:@"geometry"]objectForKey:@"location"] objectForKey:@"lng"];
location.latitude = [latitude floatValue];
location.longitude = [longitude floatValue];
driverMarker.position = CLLocationCoordinate2DMake(location.latitude, location.longitude);
driverMarker.map = mapView;
}
driverMarker.icon=[UIImage imageNamed:@"marker"];
bounds = [bounds includingCoordinate:driverMarker.position];
driverMarker.title = @"My locations";
[driverMarker setTappable:NO];
mapView.myLocationEnabled = YES;
}
【问题讨论】:
-
你在哪里声明
driveMarker?似乎您只有其中一个,因此在您的for循环中,您总是会覆盖该值,而旧的值会被 ARC 释放。 -
driverMarker 在循环中..我应该在视图加载时使用它吗?..我在 viewdidload 处分配初始化 driverMarker 但没有任何变化..标记没有显示
标签: ios objective-c google-maps-markers google-maps-sdk-ios