Reputation: 21
i have a problem while using google maps route in iphone app development.
NSString* apiUrlStr = [NSString stringWithFormat:@"http://www.maps.google.com/maps?output=dragdir&saddr=%@&daddr=%@", saddr, daddr];
it returns 404 error : Page not found
what should be the problem?
Upvotes: 1
Views: 666
Reputation: 6921
Your URL is not correct, you should use @"http://www.maps.google.com/maps?saddr=%@&daddr=%@"
if you try to launch Google Maps from iPhone's web browser. Sample URL: http://www.maps.google.com/maps?saddr=22.990236,72.603676&daddr=23.023537,72.529091
For more details about Google Maps URL Scheme, you can visit this documentation.
If you want to launch the native iOS Google Maps from your iPhone, you can do the following:
- (void)test {
NSURL *appURL = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"comgooglemaps://?saddr=%@&daddr=%@", @"22.990236,72.603676", @"23.023537,72.529091"]];
NSURL *webURL = [[NSURL alloc] initWithString:[NSString stringWithFormat:@"http://www.maps.google.com/maps?saddr=%@&daddr=%@", @"22.990236,72.603676", @"23.023537,72.529091"]];
// If can launch from native iOS Google Maps app
if ([[UIApplication sharedApplication] canOpenURL:appURL]) {
[[UIApplication sharedApplication] openURL:appURL];
}
// Launch from web browser, if no native iOS Google Maps app installed
else {
[[UIApplication sharedApplication] openURL:webURL];
}
}
If you just want to draw routes in your MapView, you can use Google Maps Directions Service, you can visit this documentation for details about using the Directions Request URL.
Upvotes: 2
Reputation: 2751
you havent explained what u need..
if u need to show a location on map in iPhone go for IOS MapKit FrameWork. its easy.
Select ur project.. in build settings (General) add MapKit FrameWork.. go to ur xib file or storyBoard whatever u r using .Now u can see MKMapView in object library. Drag MkMapView in ur xib.
in coding part
MKPointAnnotation* annotation = [[MKPointAnnotation alloc] init];
CLLocationCoordinate2D myCoordinate;
myCoordinate.latitude=(latitude);
myCoordinate.longitude=(longtitude);
annotation.coordinate = myCoordinate;
annotation.title =@"";
annotation.subtitle=@"";
//u can set the area currently displayed by the map view.
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(myCoordinate, 1000, 1000);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
[_mapView addAnnotation:annotation];
Upvotes: 0