使用Google Map sdk在ios中从GMSMapview中删除特定的GMSMarker [英] Remove particular GMSMarker from GMSMapview using Google Map sdk in ios
问题描述
我正在整合Google地图sdk。它的一切正常。但是如何在第二个出现时删除特定标记(Pin Point)(我没有使用Mapkit)
我想要下列内容:
如果我点击地图,那么现在在该位置生成一个标记针,如果我点击地图上的另一个位置,则会显示两个针,但是我想移除旧的标记针。
我也使用,
[self.mapView clear];
但是很清楚GMSMapview的所有其他标记点。
以下是在Map上添加pin的代码:
GMSMapView * mapView;
GMSMarker * currLocMarker = [[GMSMarker alloc] init];
currLocMarker.map = nil;
[currLocMarker setTitle:NSLocalizedString(@current_location_title,nil)];
currLocMarker.icon = [UIImage imageNamed:@pin_fetch_location.png];
currLocMarker.position = CLLocationCoordinate2DMake(pCoordinate.latitude,pCoordinate.longitude);
currLocMarker.map = self.mapView;
请帮我解决这个问题.. !!
在此先感谢..:)
是的,我找到了解决方案。
添加以下引脚:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate :( CLLocationCoordinate2D)坐标{
pCoordinate.latitude = coordinates.latitude;
pCoordinate.longitude = coordinates.longitude;
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(coordinates.latitude,coordinates.longitude)completionHandler:^(GMSReverseGeocodeResponse * resp,NSError * error)
{
[currLocMarker setTitle: NSLocalizedString(@current_location_title,nil)];
currLocMarker.icon = [UIImage imageNamed:@pin.png];
currLocMarker.position = CLLocationCoordinate2DMake(coordinates.latitude,coordinates.longitude);
currLocMarker.map = self.mapView;}];}
请删除以下行如果你在上面使用过:
GMSMarker * currLocMarker = [[GMSMarker alloc] init];
I am integrating google maps sdk. Its all work fine. But how to remove particular Marker(Pin Point) when second will appear.(I am not using Mapkit)
I want the following:
If i tap on map then one marker pin is generate at that location now if i tap on another location on map then two pins are displayed but i want to remove the old marker pin.
I also use,
[self.mapView clear];
But it was clear all other marker points from GMSMapview.
Following is the code to add pin on Map:
GMSMapView *mapView;
GMSMarker *currLocMarker = [[GMSMarker alloc] init];
currLocMarker.map = nil;
[currLocMarker setTitle:NSLocalizedString(@"current_location_title", nil)];
currLocMarker.icon = [UIImage imageNamed:@"pin_fetch_location.png"];
currLocMarker.position = CLLocationCoordinate2DMake(pCoordinate.latitude, pCoordinate.longitude);
currLocMarker.map = self.mapView;
Please help me to solve out this stuff..!!
Thanks in advance..:)
Yes, I got that solution. Add pin like the following:
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinates {
pCoordinate.latitude =coordinates.latitude;
pCoordinate.longitude =coordinates.longitude;
[[GMSGeocoder geocoder] reverseGeocodeCoordinate:CLLocationCoordinate2DMake(coordinates.latitude, coordinates.longitude) completionHandler:^(GMSReverseGeocodeResponse *resp, NSError *error)
{
[currLocMarker setTitle:NSLocalizedString(@"current_location_title", nil)];
currLocMarker.icon = [UIImage imageNamed:@"pin.png"];
currLocMarker.position = CLLocationCoordinate2DMake(coordinates.latitude, coordinates.longitude);
currLocMarker.map = self.mapView;} ] ;}
Please remove the following line if you used in the above:
GMSMarker *currLocMarker = [[GMSMarker alloc] init];
这篇关于使用Google Map sdk在ios中从GMSMapview中删除特定的GMSMarker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!