我正在开发一个iPhone应用程序,我在工具栏上提供了Pin Annotation按钮。当用户单击按钮时,引脚将放在地图视图的中心。现在我希望那个用户移动那个引脚并放置在他们想要的位置,我将获得该点的经度和经度。那么我如何用我的地图视图定义所有这些事件?怎么样?我得到这个代码来添加注释。
- (void)addPinAnnotation:(id)sender {
UICRouteAnnotation *pinAnnotation = [[[UICRouteAnnotation alloc] initWithCoordinate:[routeMapView centerCoordinate]
title:nil
annotationType:UICRouteAnnotationTypeWayPoint] autorelease];
[routeMapView addAnnotation:pinAnnotation];
}
如何获得该点的纬度和经度?
提前致谢....
答案 0 :(得分:1)
- (void)locationManager:(CLLocationManager *)manager didUpdateToLocation:(CLLocation *)newLocation fromLocation:(CLLocation *)oldLocation {
// Add annotation to map
MKCoordinateRegion reg;
CLLocationCoordinate2D location = newLocation.coordinate ;
reg.center = location;
MKCoordinateSpan span;
span.latitudeDelta = 1.5;
span.longitudeDelta = 1.5;
reg.span = span;
reg.center=newLocation.coordinate;
[self.mapView setRegion:reg animated:TRUE];
annotation = [[myAnnotation alloc] initWithCoordinate:newLocation.coordinate title:@"Click > to set or drag to move"];
[self.mapView addAnnotation:annotation];
[self.mapView selectAnnotation:annotation animated:YES];
[manager stopUpdatingLocation];
[loading stopAnimating];
}