【问题标题】:Launch Google maps app from iPhone application.从 iPhone 应用程序启动 Google 地图应用程序。
【发布时间】:2009-10-14 01:53:31
【问题描述】:

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

启动部分运行良好,但自从 iPhone 3.1 更新以来(我想是在这个时候),我得到了一张缩小的美国和加拿大地图,而不是放大了我当前的位置。最初一切正常,但有时在更新前后事情停止正常工作。

这是我一直在使用的字符串。这适用于我的合作伙伴的 iOS 3.0 手机和我们的 iOS 2.2.1 iPod,但在我的 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];

非常感谢任何帮助。

提前致谢。

【问题讨论】:

  • 您的 latitudeString 和 longitudeString 中有什么?无法从显示的代码中分辨出来。另外,latlong变量是不需要的,我认为你不需要latlong字符串上的stringByAddingPercentEscapesUsingEncoding,它应该只是一个浮点数。
  • 下面是我尝试的最后一个字符串。 NSURL *aURL = [NSURL URLWithString:@"maps.google.com/…; 我也尝试了以下字符串。NSURL *aURL = [NSURL URLWithString:@"maps.google.com/…; NSURL *aURL = [NSURL URLWithString:@"maps.google.com/…; 谢谢

标签: ios iphone objective-c google-maps uiapplication


【解决方案1】:

这是我在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]; 

【讨论】:

  • 这不能满足我的需要。看起来这是用来指示从一个位置到另一个位置的方向。我正在寻找围绕给定纬度和经度的搜索词。我注意到一些有趣的事情。在网络浏览器中使用以下 URL 可以放大我的位置和搜索结果的地图,但是当我在 iPhone 应用程序中使用相同的 URL 时,我会得到一张美国和加拿大的缩小地图,其中包含 10 个搜索结果。 NSURL *aURL = [NSURL URLWithString:@"maps.google.com/maps?q=clothes&ll=45.505,-122.63"]; [urlString release]; [[UIApplication sharedApplication] openURL:aURL]; 有什么想法吗?
  • 我敢打赌谷歌地图正在缩小以显示所有搜索结果。看起来您可以使用 &z= 设置地图缩放级别和 &radius= 设置搜索半径。像这样:maps.google.com/…
  • 不幸的是,这也不起作用。这似乎是 3.1 与 3.0 的问题,因为它在我的合作伙伴手机上运行良好,使用 3.0。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-03-31
  • 2011-01-06
相关资源
最近更新 更多