2011-07-11 92 views
0

我試圖從我的應用程序啓動Google地圖應用程序。在地圖應用程序中,我要設置目的地,並且用戶決定使用他的當前位置或輸入地址。任何人都可以指導我如何繼續這個。我絕對不知道這件事。從我的應用程序啓動Google地圖應用程序iphone

感謝

回答

0

要加載,您可以使用

mapView.showsUserLocation = YES; 

找到你需要使用谷歌API如下位置的當前位置。

-(CLLocationCoordinate2D)findTheLocation{ 
    NSString *url = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",[addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 

    NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:url] encoding:NSUTF8StringEncoding error:NULL]; 

    NSArray *addressItems = [locationString componentsSeparatedByString:@","]; 
    NSLog(@"Address URL : %@", locationString); 
    double latitude; 
    double longitude; 

    if ([addressItems count] >=4 && [[addressItems objectAtIndex:0] isEqualToString:@"200"]) { 
     latitude = [[addressItems objectAtIndex:2] doubleValue]; 
     longitude = [[addressItems objectAtIndex:3] doubleValue]; 
    } 
    else { 
     NSLog(@"Address error....."); 
    } 
    CLLocationCoordinate2D coord; 
    coord.latitude = latitude; 
    coord.longitude = longitude; 
    return coord; 
} 

上面的函數將返回地址的座標。你可以在地圖上顯示這個協調。 我希望這會幫助你。

+0

非常感謝。但我試圖從我的應用程序啓動谷歌地圖應用程序,並設置最終目的地。你能告訴我如何調用谷歌地圖應用程序? – pa12

+0

以下教程將爲您提供答案。 [鏈接](http://www.edumobile.org/iphone/iphone-programming-tutorials/mapkit-example-in-iphone/) 您可以將您的目標座標設置爲'region.center' – Chinthaka

3
[[UIApplication sharedApplication] openURL:[NSURL URLWithString: @"http://maps.google.com/maps?q=INSERT_YOUR_QUERY_HERE"]] 
+0

你能告訴我我們如何查詢網址?對不起。我完全不知道谷歌地圖 – pa12

相關問題