如何在目标c中找到所选位置的坐标(纬度和经度) [英] how to find the co-ordinates(lati&long) of a selected location in objective c

查看:109
本文介绍了如何在目标c中找到所选位置的坐标(纬度和经度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Google Autocomplete API,但正在获取地名和占位符,但无法获取该地名. 主席先生,我如何找到座标.

I am using Google Autocomplete API and i am getting the place name and placeid but I am unable to get the co-rdinate of the place. Sir, how can i find the co-ordinate.

 GMSAutocompleteFilter *filter = [[GMSAutocompleteFilter alloc] init];
    filter.type = kGMSPlacesAutocompleteTypeFilterCity;

    [_placesClient autocompleteQuery:@"s"//this should be your textfield text
                              bounds:nil
                              filter:filter
                            callback:^(NSArray *results, NSError *error) {
                                if (error != nil) {
                                    NSLog(@"Autocomplete error %@", [error localizedDescription]);
                                    return;
                                }

                                for (GMSAutocompletePrediction* result in results) {


                                    NSDictionary *aTempDict =  [NSDictionary dictionaryWithObjectsAndKeys:result.attributedFullText.string,@"description",result.placeID,@"reference", nil];
                                    PlaceObject *placeObj=[[PlaceObject alloc]initWithPlaceName:[aTempDict objectForKey:@"description"]];
                                    placeObj.userInfo=aTempDict;
                                    //                                    [finalarray addObject:placeObj];
                                    NSLog(@"Result '%@' with placeID %@", result.attributedFullText.string, result.placeID);
                                    NSLog(@"%@",finalarray);
                                    [finalarray addObject:result.attributedFullText.string];
                                    NSString *aStrPlaceReferance=[placeObj.userInfo objectForKey:@"reference"];

                                          NSLog(@"%@",aStrPlaceReferance);

                                    NSString *aStrPlaceReferance1=[placeObj.userInfo objectForKey:@"description"];

                                    NSLog(@"%@",aStrPlaceReferance1);


                                }



                            }];

推荐答案

我从未使用过此API,而是从

I've never used this API but from the documentation it looks like you should use the placeID property of each GMSAutocompletePrediction object and make a new request to get the information you need.

根据本指南,您需要致电GMSPlacesClient lookUpPlaceID:callback:像这样:

According to this guide, you need to call GMSPlacesClient lookUpPlaceID:callback: like that:

// A hotel in Saigon with an attribution.
NSString *placeID = @"ChIJV4k8_9UodTERU5KXbkYpSYs";

[_placesClient lookUpPlaceID:placeID callback:^(GMSPlace *place, NSError *error) {
  if (error != nil) {
    NSLog(@"Place Details error %@", [error localizedDescription]);
    return;
  }

  if (place != nil) {
    NSLog(@"Place name %@", place.name);
    NSLog(@"Place address %@", place.formattedAddress);
    NSLog(@"Place placeID %@", place.placeID);
    NSLog(@"Place attributions %@", place.attributions);
  } else {
    NSLog(@"No place details for %@", placeID);
  }
}];

,然后使用place.coordinate属性.

这篇关于如何在目标c中找到所选位置的坐标(纬度和经度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆