I am developing an iOS Google Map. I have the following working except that when the user drags a marker, the marker doesn't get drawn there once released. Where have I made a mistake?
我正在开发一个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];
}
1 个解决方案
#1
1
Try this :
尝试这个 :
- (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];
}
#1
1
Try this :
尝试这个 :
- (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];
}