I am using the Mapkit FrameWork for an iPhone. I have city list and its famous places, hotels and restaurants. It is finding cities and famous places on map. but not hotels and restaurants.
Here is my code:
- (CLLocationCoordinate2D) addressLocation {
NSString *strRequest; double latitude = 0, longitude = 0;
CLLocationCoordinate2D center;
NSString *strAddress = [searchLocationField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Search String:%@",searchLocationField.text);
strRequest = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", strAddress];
NSString *strNewResult = [NSString stringWithContentsOfURL:[NSURL URLWithString:strRequest] encoding:NSUTF8StringEncoding error:NULL];
NSLog(@"StrRequest :- '%@'",strNewResult);
NSArray *listItems = [strNewResult componentsSeparatedByString:@","];
if([listItems count] == 4)
{
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Warning"
message:@"Could Not Find Address"
开发者_如何学编程 delegate:nil
cancelButtonTitle:@"ok"
otherButtonTitles:nil];
[alert show];
[alert release];
}
center.latitude = latitude;
center.longitude = longitude;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(center, 1000, 1000);
MKCoordinateRegion adjustRegion = [mapView regionThatFits:region];
[mapView setRegion:adjustRegion animated:YES];
return center;
}
Is there any way to find an exact location??
You would need to monitor the exact location changes in -didUpdateToLocation. That is constantly called updating your current location for as long as [locationManager startUpdatingForLocation] is running.
When you use the region monitoring, you are only going to get 2 events, -didEnterRegion and -didExitRegion. Depending on what you are doing, the region monitoring may not be the best tool for this application.
精彩评论