gpt4 book ai didi

ios - 拖动时不添加标记 - Google map iOS 应用

转载 作者:行者123 更新时间:2023-11-29 00:26:37 24 4
gpt4 key购买 nike

我正在开发 iOS 谷歌地图。我有以下工作,除了当用户拖动标记时,标记一旦释放就不会被绘制在那里。我哪里做错了?

- (void)clearAllOverlay 
{
[_mapView clear];
[self drawPolygon];
[self addMarker];
}

- (void)addMarker
{
CLLocationCoordinate2D position;
for (int i = 0; i <= [tappedCoordinates count]-1; i++) {
position.latitude = [[[tappedCoordinates objectAtIndex:i] objectAtIndex:0] floatValue];
position.longitude = [[[tappedCoordinates objectAtIndex:i] objectAtIndex:1] floatValue];
GMSMarker *marker = [[GMSMarker alloc] init];
marker.position = position;
marker.map = _mapView;
marker.icon = [GMSMarker markerImageWithColor:[UIColor blueColor]];
[marker setDraggable: YES];
}
}
//runs everytime user taps on marker
- (bool)mapView:(GMSMapView *)mapView didTapMarker:(GMSMarker *) marker
{
[latitudeTappedCoordinates removeObject:[NSNumber numberWithFloat:marker.position.latitude]];
[longitudeTappedCoordinates removeObject:[NSNumber numberWithFloat:marker.position.longitude]];
[self clearAllOverlay];
return 0;
}
//called while marker is dragged
- (void)mapView:(GMSMapView *)mapView didDragMarker:(GMSMarker *) marker
{
[latitudeTappedCoordinates addObject:[NSNumber numberWithFloat:marker.position.latitude]];
[longitudeTappedCoordinates addObject:[NSNumber numberWithFloat:marker.position.longitude]];

[self clearAllOverlay];
}
//runs everytime user taps on any coordinate, except marker
- (void)mapView:(GMSMapView *)mapView didTapAtCoordinate:(CLLocationCoordinate2D)coordinate
{
// store tapped coordinates in multi-dimensional array
NSArray *array = @[[NSNumber numberWithFloat:coordinate.latitude], [NSNumber numberWithFloat:coordinate.longitude]];
[tappedCoordinates addObject:array];
[latitudeTappedCoordinates addObject:[NSNumber numberWithFloat:coordinate.latitude]];
[longitudeTappedCoordinates addObject:[NSNumber numberWithFloat:coordinate.longitude]];
[self clearAllOverlay];
}

最佳答案

试试这个:

- (void) mapView:(GMSMapView *) mapViewdidEndDraggingMarker:(GMSMarker *)   marker {
// store tapped coordinates in multi-dimensional array
NSArray *array = @[[NSNumber numberWithFloat:marker.position.latitude], [NSNumber numberWithFloat:marker.position.longitude]];
[tappedCoordinates addObject:array];
[latitudeTappedCoordinates addObject:[NSNumber numberWithFloat:marker.position.latitude]];
[longitudeTappedCoordinates addObject:[NSNumber numberWithFloat:marker.position.longitude]];
[self clearAllOverlay];

}

关于ios - 拖动时不添加标记 - Google map iOS 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42843671/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com