我如何在 MapView 中使用 Pin Point 显示位置名称

How i can show the location name with Pin Point in MapView

我想在我的 mapView.I 中显示位置名称和针点 尝试了很多方法,但其中 none 对我有帮助。我被困在这个位置上。 我正在使用这段代码:

-(void)getMe:(id)sender
{
[self.view endEditing:YES];
NSString *addresss = userText.text;
NSString *esc_addr = [addresss stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSString *req = [NSString stringWithFormat: @"http://maps.google.com/maps/api/geocode/json?sensor=false&address=%@", esc_addr];

NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:req]];


NSDictionary  *googleResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];

NSDictionary *resultsDict = [googleResponse valueForKey:  @"results"];   // get the results dictionary
NSDictionary *geometryDict = [   resultsDict valueForKey: @"geometry"];   // geometry dictionary within the  results dictionary
NSDictionary *locationDict = [  geometryDict valueForKey: @"location"];   // location dictionary within the geometry dictionary

// nslo (@”– returning latitude & longitude from google –”);

NSArray *latArray = [locationDict valueForKey: @"lat"]; NSString *latString = [latArray lastObject];     // (one element) array entries provided by the json parser
NSArray *lngArray = [locationDict valueForKey: @"lng"]; NSString *lngString = [lngArray lastObject];     // (one element) array entries provided by the json parser

myLocation.latitude = [latString doubleValue];     // the json parser uses NSArrays which don’t support “doubleValue”
myLocation.longitude = [lngString doubleValue];

CLLocationCoordinate2D zoomLocation;
zoomLocation.latitude = myLocation.latitude;
zoomLocation.longitude=myLocation.longitude;

// 2
MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(zoomLocation, 0.5*1500, 0.5*1500);

MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D coordinates;
coordinates.latitude = myLocation.latitude;
coordinates.longitude=myLocation.longitude;
point.coordinate =coordinates;
point.title = @"My Location";
point.subtitle = @"Reached";

[mp addAnnotation:point];
// 3
[mp setRegion:viewRegion animated:YES];
}

mp 是我的 mapView Outlet.I 我得到这个输出:

但我想要带有 pin 的位置标题。我该怎么做才能实现这一目标。

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

// Add an annotation
MKPointAnnotation *point = [[MKPointAnnotation alloc] init];
point.coordinate = userLocation.coordinate;
point.title = @"Where am I?";
point.subtitle = @"I'm here!!!";

[self.mapView addAnnotation:point];
}