2013-07-11 39 views
1

我想添加谷歌地图到我的应用程序在地图视图中,我想把功能,如在whatsapp。通过提供附近的地方,搜索栏和分享我的当前位置。 任何机构都可以帮助我并告诉我是否有需要向Google或任何地方购买或要求购买的东西?谷歌地图API使用故事板

回答

1

最初,为了获取地图运行,你可以按照你可以搜索在给定位置附近的地方this page

显示随着Google Places API的步骤。或者您可以根据字符串搜索位置。

要得到您当前的位置,您可以看到如何去做here

你不必购买任何东西。尽管Google API存在访问限制。例如,Google地方信息只允许您每天处理1,000个请求。 iOS版Google地图SDK不会限制请求。

以下是我的代码片段,用于访问Google Places API。

NSString * key = @"PUT YOUR KEY HERE"; 
NSString * html_msg = [msg stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; 
NSString * address = [NSString stringWithFormat: @"https://maps.googleapis.com/maps/api/place/textsearch/json?sensor=false&key=%@&query=%@", key, html_msg]; 
//Create URL and Request 
NSURL * url = [NSURL URLWithString:address]; 
NSURLRequest * request = [NSURLRequest requestWithURL:url]; 
NSURLResponse * response; 
NSError * error = nil; 
//Send Request 
NSData * data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]; 
if (error == nil) { 
    //Parse JSON to Dictionary 
    NSDictionary * json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; 
    //Get the lat/lng of the first result 
    [json[@"results"][0][@"geometry"][@"location"][@"lat"] doubleValue]; 
    [json[@"results"][0][@"geometry"][@"location"][@"lng"] doubleValue]; 
} 
1

我不知道都包括在WhatsApp的什么功能,但谷歌搜索告诉我,有一个谷歌地图SDK,与功能,应该允许您创建一个“高度互动的”应用程序。它似乎没有花费任何东西,但你确实需要信任谷歌。这里是他们网站的链接:https://developers.google.com/maps/documentation/ios/