开发者

Launch Google maps app from iPhone application.

开发者 https://www.devze.com 2022-12-09 00: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 tim开发者_StackOverflowe) I get a zoomed out ma

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 tim开发者_StackOverflowe) 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.


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]; 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号