简体   繁体   中英

How to add annotation in Map view In Iphone

I want to place an annotation on the Map view from the address typed in a text field using the MapKit instead of longitude and latitude in iphone.Whether is it possible to do that?If yes,how. Please provide some sample code to do this. Thanx in advance

You have to get the lat/long via some manner (geocoding). Here's an example I found on an excellent MKMapView tutorial:

NSString * address = @”1600 Pennsylvania Ave, Washington DC”; // address here

NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
NSArray *listItems = [locationString componentsSeparatedByString:@","];
double latitude = 0.0;
double longitude = 0.0;
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@”200″]) {
  latitude = [[listItems objectAtIndex:2] doubleValue];
  longitude = [[listItems objectAtIndex:3] doubleValue];
}
else {
  //Error handling
}

From http://www.invasivecode.com/2009/07/adding-maps-to-your-iphone-app-mapkit/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM