2009-10-14 164 views
4

我试图从我的iPhone应用程序启动谷歌地图。从iPhone应用程序启动Google地图应用程序。

启动部分工作正常,但自从iPhone 3.1更新(我想这是在这个时间左右),我得到了一个缩小的美国和加拿大的地图,而不是放大我的当前位置。一切工作正常,但有时更新的东西停止正常工作。

这是我一直在使用的字符串。这适用于我的合作伙伴手机与iOS 3.0和我们的iPod与iOS 2.2.1,但我的手机与iOS 3.1显示一个缩小的加拿大和美国的地图。

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

任何帮助,非常感谢。

在此先感谢。

+0

什么在你的latitudeString和longitudeString?从显示的代码无法分辨。另外,latlong变量不是必需的,我不认为你需要在latlong字符串上使用stringByAddingPercentEscapesUsingEncoding,它应该只是一个浮点数。 – progrmr 2009-10-14 15:49:33

+0

下面是我尝试过的最后一个字符串。 NSURL * aURL = [NSURL URLWithString:@“http://maps.google.com/maps?q=clothes&ll=45.505,-122.63&radius=30 &z=8"]; 我也试过以下字符串 NSURL * aURL。 = [NSURL URLWithString:@“http://maps.google.com/maps?q=liquor&z=13&sll=30.290525,-97.745706”]; NSURL * aURL = [NSURL URLWithString:@“http:// maps。 google.com/maps?q=liquor&ll=45.505,-122.63&mrt=yp&z=13“]; 谢谢 – jmurphy 2009-10-15 00:52:05

回答

3

这是我在one of my apps中使用的代码,它在3.1中正常工作。谷歌地图的参数是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

这并不给我我需要的东西,看起来像这是用来给出从一个位置到另一个位置的方向。我正在寻找一个关于给定纬度和经度的搜索字词 我注意到一些有趣的东西。在网络浏览器中使用下面的URL给我一个动物园med在我的位置和搜索结果的地图上,但是当我在iPhone应用程序中使用相同的URL时,我会用10个搜索结果获取美国和加拿大的缩小地图。 \t NSURL * aURL = [NSURL URLWithString:@“http://maps.google.com/maps?q=clothes&ll=45.505,-122.63”]; \t [urlString release]; \t [[UIApplication sharedApplication] openURL:aURL]; 任何想法? – jmurphy 2009-10-14 06:19:50

+0

我敢打赌谷歌地图正在缩小,以显示所有的搜索结果。看起来您可以使用&z =设置地图缩放级别,使用&半径=设置搜索半径。像这样:http://maps.google.com/maps?q=clothes&ll=45.505,-122.63&radius=30&z=8 – progrmr 2009-10-14 16:02:50

+0

不幸的是,这也没有奏效。看起来这是一个3.1 vs 3.0的问题,因为它可以在我的伙伴手机3.0上正常工作。 – jmurphy 2009-10-15 00:49:24

相关问题