GMSMarker iOS问题
我使用这段代码在谷歌地图上为iOS创建标记GMSMarker iOS问题,ios,google-maps,google-maps-api-3,gmsmapview,Ios,Google Maps,Google Maps Api 3,Gmsmapview,我使用这段代码在谷歌地图上为iOS创建标记 self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera]; self.mapView.myLocationEnabled = YES; self.mapView.accessibilityElementsHidden = NO; self.mapView.frame = self.view.bounds; self.mapView.autoresi
self.mapView = [GMSMapView mapWithFrame:CGRectZero camera:camera];
self.mapView.myLocationEnabled = YES;
self.mapView.accessibilityElementsHidden = NO;
self.mapView.frame = self.view.bounds;
self.mapView.autoresizingMask = UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
self.mapView.delegate = self;
self.mapView.settings.myLocationButton = YES;
[self.view addSubview:self.mapView];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20);
marker.map = self.mapView;
但我需要一个像这样的标记:
marker.icon = image; // image from xib file
我知道如何使用苹果地图,但我需要使用谷歌地图(因为在一些城市,苹果地图几乎什么都不显示)
对于google map,我只找到如下代码:
marker.icon = image; // image from xib file
所以我需要为每个标记从xib创建图像。我会有很多标记,所以可能用这种方法我会得到记忆警告
有谁知道更好的方法来实现这样的标记吗?据我所知,这是唯一的方法。但是你可以按照谷歌的最佳实践来限制谷歌地图上的标记,以防止内存或性能问题。。阅读以更好地理解。好的按照这个例子,实现您想要的非常简单:
- 声明uiimageview
- 声明第二个imageview(您想要的显示在fiist中,在本例中是b&w中的女孩)
- 因此,将第二个图像作为子视图添加到第一个图像中
- 现在你可以将第一个图像添加到marker.icon=(这里是第一个图像!!)李>
希望这能对你有所帮助。因为GMSMarker只允许将UIImage设置为图标,所以我实现了类似的功能: (在Swift中,但目标C的概念相同) 其中,函数imageFromView如下所示:
private func imageFromView(aView:UIView) -> UIImage {
if(UIScreen.mainScreen().respondsToSelector("scale")) {
UIGraphicsBeginImageContextWithOptions(aView.frame.size, false, UIScreen.mainScreen().scale)
}
else {
UIGraphicsBeginImageContext(aView.frame.size)
}
aView.layer.renderInContext(UIGraphicsGetCurrentContext())
var image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image
}
希望这能有所帮助。首先将颜色设置为标记,然后将相机位置设置为该坐标,以便在应用程序启动时重定向到该坐标
Set the color to your marker first and then camera position to that coordinate, So that whenever your app will start it redirect to that coordinate
marker.icon = [UIColor redColor];
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithPath:< CLLocationCoordinate2DMake>];
[self.mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:10.0f]];
bounds=nil;
GMSCoordinateBounds *bounds = [[GMSCoordinateBounds alloc] initWithPath:path];
[self.mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds withPadding:0.0f]];
bounds=nil;
marker.icon=[UIColor redColor];
GMSCoordinateBounds*bounds=[[GMSCoordinateBounds alloc]initWithPath:];
[self.mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds with padding:10.0f];
界=零;
GMSCoordinateBounds*bounds=[[GMSCoordinateBounds alloc]initWithPath:path];
[self.mapView animateWithCameraUpdate:[GMSCameraUpdate fitBounds:bounds with padding:0.0f];
界限=零;
我认为您需要为许多标记实现集群。您能给出任何链接或代码示例吗?“多个标记的群集”是否有助于仅显示视图标记,或有助于在标记中显示自定义视图?请看,它确实有帮助,非常感谢,请接受我的投票。您能在对象c中提供方法吗?