2009-10-14 162 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

相關問題