我必须在IOS中的谷歌地图的Marker pin上添加一个自定义标签。
我已经实现了markInfoWindow方法。但它在我点击记号笔/针后就起作用了。
我需要在开始时显示自定义标签,只要地图视图将加载到视图上而不执行任何操作。由于我们可以在标记上设置图标或标题,我需要在上面显示我自己的自定义视图。
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
CLLocationCoordinate2D anchor = marker.position;
// CGPoint point = [mapView.projection pointForCoordinate:anchor];
// self.calloutView.title = marker.title;
[self.calloutView setFrame:CGRectMake(0, 50, 25, 25)];
self.calloutView.layer.cornerRadius = 11.0;
self.calloutView.layer.masksToBounds = YES;
self.calloutView.layer.borderColor = [UIColor clearColor].CGColor;
self.calloutView.layer.borderWidth = 0.0;
self.calloutView.hidden = NO;
return self.calloutView;
}
使用此代码为GMSMarker:添加图像
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = MARKER_POSITION;
marker.infoWindowAnchor = CGPointMake(0.44f, 0.45f);
marker.icon = [UIImage imageNamed:@"CustomMarkerImageName"];
您也可以使用此委托方法为其他信息提供自定义视图:
- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
InfoWindow *view = [[[NSBundle mainBundle] loadNibNamed:@"InfoWindow" owner:self options:nil] objectAtIndex:0];
view.name.text = @"Place Name";
view.description.text = @"Place description";
view.phone.text = @"123 456 789";
view.placeImage.image = [UIImage imageNamed:@"customPlaceImage"];
view.placeImage.transform = CGAffineTransformMakeRotation(-.08);
return view;
}
请将此答案作为参考:https://stackoverflow.com/a/16767124/2082569
如果我理解正确,那么任务是以编程方式显示特定标记的信息窗口。
[self.mapView setSelectedMarker:marker];
要实现类似于用户点击标记的相机重新聚焦,请执行以下操作:
GMSCameraPosition *cameraPosition =
[[GMSCameraPosition alloc] initWithTarget:marker.position
zoom:15
bearing:0
viewingAngle:0];
[self.mapView animateToCameraPosition:cameraPosition];