简体   繁体   English

从我的应用程序 iphone 启动谷歌地图应用程序

[英]Launcing google maps app from my app iphone

I am trying to launch Google maps app from my app.我正在尝试从我的应用程序启动 Google 地图应用程序。 In the maps app I was to set the destination and the user decides to use his current location or enter address.在地图应用程序中,我要设置目的地,用户决定使用他当前的位置或输入地址。 Can any one guide me how to proceed with this.任何人都可以指导我如何进行此操作。 I absolute have no idea about this.我绝对不知道这一点。

Thanks谢谢

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

To load the current location you can use要加载当前位置,您可以使用

mapView.showsUserLocation = YES;

To find the location you need to use google API as follows.要找到您需要使用 google 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;
}

Above function will return the coordinates of the address.上面 function 会返回地址的坐标。 You can display this coordination on map.您可以在 map 上显示此协调。 I hope this will help you.我希望这能帮到您。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM