用于IOS标记的Google Maps SDK正在被覆盖
我在使用Google Maps SDK for iOS(1.5.0版)绘制多个标记时遇到问题。我不熟悉objective c(使用Xcode 4.6.3版)和Google Maps SDK,所以我可能遗漏了一些明显的东西。我也在使用iOS 6.1模拟器。我试着在实践中学习 我花了几天的时间搜索,找到了一些解决这个问题的方法,但没有一个对我有效。我遇到的问题是,我的标记正在相互覆盖。我创建了一个NSArray,locations,它将有4列和未知行。列为纬度、经度、名称和地址用于IOS标记的Google Maps SDK正在被覆盖,ios,objective-c,google-maps-sdk-ios,Ios,Objective C,Google Maps Sdk Ios,我在使用Google Maps SDK for iOS(1.5.0版)绘制多个标记时遇到问题。我不熟悉objective c(使用Xcode 4.6.3版)和Google Maps SDK,所以我可能遗漏了一些明显的东西。我也在使用iOS 6.1模拟器。我试着在实践中学习 我花了几天的时间搜索,找到了一些解决这个问题的方法,但没有一个对我有效。我遇到的问题是,我的标记正在相互覆盖。我创建了一个NSArray,locations,它将有4列和未知行。列为纬度、经度、名称和地址 for(int i=
for(int i=0;i<[locations count];i++){
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.0823
longitude:-74.2234
zoom:7];
mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = mapView_;
mapView_.myLocationEnabled = YES;
mapView_.mapType = kGMSTypeHybrid;
mapView_.settings.myLocationButton = YES;
mapView_.settings.zoomGestures = YES;
mapView_.settings.tiltGestures = NO;
mapView_.settings.rotateGestures = NO;
NSString *lat = [[locations objectAtIndex:i] objectAtIndex:0];
NSString *lon = [[locations objectAtIndex:i] objectAtIndex:1];
double lt=[lat doubleValue];
double ln=[lon doubleValue];
NSString *name = [[locations objectAtIndex:i] objectAtIndex:2];
NSMutableArray *markersArray = [[NSMutableArray alloc] init];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.appearAnimation=YES;
marker.position = CLLocationCoordinate2DMake(lt,ln);
marker.title = name;
marker.snippet = [[locations objectAtIndex:i] objectAtIndex:3];
marker.map = mapView_;
[markersArray addObject:marker];
}
for(int i=0;i我发现一些可能相关的错误。每次迭代for循环中的locations数组时,都会覆盖markersArray。在for循环之外实例化markersArray
你能记录下你要画的每个标记的坐标吗
如果坐标相同,则标记应在彼此的正上方绘制,使标记看起来被覆盖,但它们正好位于彼此的正上方
完成后,记录位置和markersArray的计数,以确保它们彼此相等,作为快速检查
*编辑:我看到了您的问题。每次迭代for循环时,您都会覆盖MapView
试着这样做:
// Create a markersArray property
@property (nonatomic, strong) NSMutableArray *markersArray;
// Create a GMSMapView property
@property (nonatomic, strong) GMSMapView *mapView_;
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupMapView];
[self plotMarkers];
}
// Lazy load the getter method
- (NSMutableArray *)markersArray
{
if (!_markersArray) {
_markersArray = [NSMutableArray array];
}
return _markersArray;
}
- (void)setupMapView
{
self.mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = self.mapView_;
self.mapView_.myLocationEnabled = YES;
self.mapView_.mapType = kGMSTypeHybrid;
self.mapView_.settings.myLocationButton = YES;
self.mapView_.settings.zoomGestures = YES;
self.mapView_.settings.tiltGestures = NO;
self.mapView_.settings.rotateGestures = NO;
// You also instantiate a GMSCameraPosition class, but you don't add it to your mapview
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.0823
longitude:-74.2234
zoom:7];
}
- (void)plotMarkers
{
// I don't know how you're creating your locations array, so I'm just pretending
// an array will be returned from this fake method
NSArray *locations = [self loadLocations];
for (int i=0; i<[locations count]; i++){
NSString *lat = [[locations objectAtIndex:i] objectAtIndex:0];
NSString *lon = [[locations objectAtIndex:i] objectAtIndex:1];
double lt=[lat doubleValue];
double ln=[lon doubleValue];
NSString *name = [[locations objectAtIndex:i] objectAtIndex:2];
// Instantiate and set the GMSMarker properties
GMSMarker *marker = [[GMSMarker alloc] init];
marker.appearAnimation=YES;
marker.position = CLLocationCoordinate2DMake(lt,ln);
marker.title = name;
marker.snippet = [[locations objectAtIndex:i] objectAtIndex:3];
marker.map = self.mapView_;
[self.markersArray addObject:marker];
}
}
//创建markersArray属性
@属性(非原子,强)NSMutableArray*markersArray;
//创建GMSMapView属性
@属性(非原子,强)GMSMapView*mapView;
-(无效)viewDidLoad
{
[超级视图下载];
[自设置地图视图];
[自我描绘标记];
}
//延迟加载getter方法
-(NSMutableArray*)标记数组
{
if(!\u标记数组){
_markersArray=[NSMutableArray];
}
返回标记数组;
}
-(无效)setupMapView
{
self.mapView=[GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view=self.mapView;
self.mapView_uz.myLocationEnabled=是;
self.mapView\uu.mapType=kGMSTypeHybrid;
self.mapView\u.settings.myLocationButton=是;
self.mapView\u.settings.zoomGestures=YES;
self.mapView\uu.settings.tiltsignities=否;
self.mapView\uu.settings.rotateGestures=否;
//您还实例化了一个GMSCameraPosition类,但没有将其添加到mapview中
GMSCameraPosition*摄像机=[GMSCameraPosition摄像机,纬度:40.0823
经度:-74.2234
缩放:7];
}
-(无效)打印标记
{
//我不知道你是如何创建位置数组的,所以我只是假装而已
//将从此假方法返回一个数组
NSArray*位置=[自加载位置];
for(int i=0;i我看到一些可能相关的错误。每次遍历for循环中的locations数组时,都会覆盖markersArray。在for循环之外实例化markersArray
你能记录下你要画的每个标记的坐标吗
如果坐标相同,则标记应在彼此的正上方绘制,使标记看起来被覆盖,但它们正好位于彼此的正上方
完成后,记录位置和markersArray的计数,以确保它们彼此相等,作为快速检查
*编辑:我看到了您的问题。每次迭代for循环时,您都会覆盖MapView
试着这样做:
// Create a markersArray property
@property (nonatomic, strong) NSMutableArray *markersArray;
// Create a GMSMapView property
@property (nonatomic, strong) GMSMapView *mapView_;
- (void)viewDidLoad
{
[super viewDidLoad];
[self setupMapView];
[self plotMarkers];
}
// Lazy load the getter method
- (NSMutableArray *)markersArray
{
if (!_markersArray) {
_markersArray = [NSMutableArray array];
}
return _markersArray;
}
- (void)setupMapView
{
self.mapView_ = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view = self.mapView_;
self.mapView_.myLocationEnabled = YES;
self.mapView_.mapType = kGMSTypeHybrid;
self.mapView_.settings.myLocationButton = YES;
self.mapView_.settings.zoomGestures = YES;
self.mapView_.settings.tiltGestures = NO;
self.mapView_.settings.rotateGestures = NO;
// You also instantiate a GMSCameraPosition class, but you don't add it to your mapview
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:40.0823
longitude:-74.2234
zoom:7];
}
- (void)plotMarkers
{
// I don't know how you're creating your locations array, so I'm just pretending
// an array will be returned from this fake method
NSArray *locations = [self loadLocations];
for (int i=0; i<[locations count]; i++){
NSString *lat = [[locations objectAtIndex:i] objectAtIndex:0];
NSString *lon = [[locations objectAtIndex:i] objectAtIndex:1];
double lt=[lat doubleValue];
double ln=[lon doubleValue];
NSString *name = [[locations objectAtIndex:i] objectAtIndex:2];
// Instantiate and set the GMSMarker properties
GMSMarker *marker = [[GMSMarker alloc] init];
marker.appearAnimation=YES;
marker.position = CLLocationCoordinate2DMake(lt,ln);
marker.title = name;
marker.snippet = [[locations objectAtIndex:i] objectAtIndex:3];
marker.map = self.mapView_;
[self.markersArray addObject:marker];
}
}
//创建markersArray属性
@属性(非原子,强)NSMutableArray*markersArray;
//创建GMSMapView属性
@属性(非原子,强)GMSMapView*mapView;
-(无效)viewDidLoad
{
[超级视图下载];
[自设置地图视图];
[自我描绘标记];
}
//延迟加载getter方法
-(NSMutableArray*)标记数组
{
if(!\u标记数组){
_markersArray=[NSMutableArray];
}
返回标记数组;
}
-(无效)setupMapView
{
self.mapView=[GMSMapView mapWithFrame:CGRectZero camera:camera];
self.view=self.mapView;
self.mapView_uz.myLocationEnabled=是;
self.mapView\uu.mapType=kGMSTypeHybrid;
self.mapView\u.settings.myLocationButton=是;
self.mapView\u.settings.zoomGestures=YES;
self.mapView\uu.settings.tiltsignities=否;
self.mapView\uu.settings.rotateGestures=否;
//您还实例化了一个GMSCameraPosition类,但没有将其添加到mapview中
GMSCameraPosition*摄像机=[GMSCameraPosition摄像机,纬度:40.0823
经度:-74.2234
缩放:7];
}
-(无效)打印标记
{
//我不知道你是如何创建位置数组的,所以我只是假装而已
//将从此假方法返回一个数组
NSArray*位置=[自加载位置];
对于(int i=0;iThanks for you input.我得花点时间看看你的答案。我的答案确实有用,因为正如你提到的,我每次都在循环中加载我的地图视图。酷,如果你还需要什么,请告诉我。谢谢你的输入。我得花点时间看看你的答案。我确实得到了我仍然在工作,因为,就像你提到的,我每次都在通过循环加载我的mapView。酷,如果你还需要什么,请告诉我。