Launch Google maps app from iPhone application.

心不动则不痛 提交于 2019-11-29 15:18:08

问题


I'm trying to launch google maps from my iPhone application.

The launching part works fine but since the iPhone 3.1 update (i think it was around this time) I get a zoomed out map of the US and Canada rather than zoomed in on my current location. Everything worked fine originally but sometime around the update things stopped working correctly.

Here is the string I've been using. This works on my partners phone with iOS 3.0 and our iPod with iOS 2.2.1 but on my phone with iOS 3.1 shows a zoomed out map of Canada and the US.

  NSString *name = @"clothing";
NSString *latlong = [[NSString alloc] initWithFormat:@"%@,%@", latitudeString, longitudeString];

NSString *url = [NSString stringWithFormat: @"http://maps.google.com/maps?q=%@&mrt=yp&ll=%@",
                      [name stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
                      [latlong stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:url]];    
[latlong release];

Any help is greatly appreciated.

Thanks in advance.


回答1:


This is the code I use in one of my apps and it works fine with 3.1. The parameters for Google maps are documented here.

CLLocationCoordinate2D stationLocation = ...

NSString *urlString = [[NSString alloc]
     initWithFormat:@"http://maps.google.com/maps?saddr=%f,%f&daddr=%f,%f&dirflg=d",
        curLocation.latitude,
        curLocation.longitude,
        stationLocation.latitude,
        stationLocation.longitude];

NSURL *aURL = [NSURL URLWithString:urlString];
[urlString release];
[[UIApplication sharedApplication] openURL:aURL]; 


来源:https://stackoverflow.com/questions/1563880/launch-google-maps-app-from-iphone-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!