0
我正在開發iOS Google Map。除了當用戶拖動一個標記時,我有以下工作,標記不會在釋放後在那裏繪製。我在哪裏犯了一個錯誤?標記不會在拖動時添加 - Google Maps 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];
}
應該是工作,但事實並非如此。 – konyv12