I want to place an annotation on the Map view from the address 开发者_JAVA技巧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/
精彩评论