8

我正在使用情节提要在视图控制器中创建地图视图。

当我使用以下代码时。

-(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    CLLocationDistance distance = 1000;   
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate,
                               distance, 
                               distance);
    MKCoordinateRegion adjusted_region = [self.mapView regionThatFits:region];
    [self.mapView setRegion:adjusted_region animated:YES];
}

在美国加利福尼亚州旧金山绘制了一个点。userLocation坐标是MapKit.h框架中的 预定义值。现在我创建一个

-(void) mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
    CLLocationDistance distance = 1000;
    CLLocationCoordinate2D myCoordinate;
    myCoordinate.latitude = 13.04016;
    myCoordinate.longitude = 80.243044;
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(myCoordinate, 
                                                                   distance, 
                                                                   distance);
    MKCoordinateRegion adjusted_region = [self.mapView regionThatFits:region];
    [self.mapView setRegion:adjusted_region animated:YES];
}

这里,以坐标为中心的区域被显示。但是,在坐标位置没有绘制任何点。

如何在该坐标位置绘制点或注释?

4

3 回答 3

11

在 didUpdateUserLocation 方法中尝试此代码

    MKPointAnnotation*    annotation = [[MKPointAnnotation alloc] init];
    CLLocationCoordinate2D myCoordinate;
    myCoordinate.latitude=13.04016;
    myCoordinate.longitude=80.243044;
    annotation.coordinate = myCoordinate;
    [self.mapView addAnnotation:annotation];
于 2013-11-20T06:15:12.820 回答
0

在 didUpdateUserLocation 中添加此代码

MKAnnotation *annotation = [[MKAnnotation alloc] initWithCoordinate:CLLocationCoordinate2DMake(latitude, longitude)];
[myMap addAnnotation:annotation];
于 2013-11-20T06:14:09.193 回答
0

试试这个.. //MAP VIEW Point

MKCoordinateRegion myRegion;

//Center
CLLocationCoordinate2D center;
center.latitude=latitude;
center.longitude=longitude;

//Span
MKCoordinateSpan span;
span.latitudeDelta=THE_SPAN;
span.longitudeDelta=THE_SPAN;

myRegion.center=center;
myRegion.span=span;

//Set our mapView
[MapViewC setRegion:myRegion animated:YES];

//Annotation

//1.create coordinate for use with the annotation
CLLocationCoordinate2D wimbLocation;
wimbLocation.latitude=latitude;
wimbLocation.longitude=longitude;

Annotation * myAnnotation= [Annotation alloc];

myAnnotation.coordinate=wimbLocation;
于 2013-11-20T06:19:22.433 回答