tags:

views:

349

answers:

1

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

+2  A: 

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/

sw
Thanx a lot for your quick reply.I just want to know the parameters of the address,means what kind of address should it be.Whether the address should contains only streets must or the state or city would be enough.Thanx once again
XcoderMi2
You'll have to investigate google maps for that
sw
Tghanx,Sw.I will do it
XcoderMi2