在Google地图上searchSdk

我需要在我的应用程序中实现地图视图来查找所需的位置。 我曾尝试过使用SVGeocoder概念。

[SVGeocoder geocode:searchfield.text completion:^(NSArray *placemarks, NSHTTPURLResponse *urlResponse, NSError *error) { } 

但是,假设我试图search任何餐饮业者,那么结果是零。

我在Google map sdk上查找,但不知道如何在GMSCameraPosition类上执行searchfunction。

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude:latitude longitude:longitude zoom:5]; 

如何使用谷歌SDKsearch地址。

提前致谢。

如果我理解正确,你需要地址string的位置坐标。 其前向地理编码。 你可以看看Google的免费api: Link1

您将需要从您的谷歌帐户的API密钥访问此API,并有办法select一个免费或商业计划取决于您的请求数量。

你需要使用一个CLLocation对象来获得你的地址的坐标。 我写了一个类似的function。

CLLocation* temp_location=[[CLLocation alloc]init]; temp_location=[GeoCoding findAddressCordinates:sourceAddressTxtField.text];

//类GeoCoding查找坐标

 #import <Foundation/Foundation.h> @interface GeoCoding : NSObject { } +(CLLocation*)findAddressCordinates:(NSString*)addressString; @end #import "GeoCoding.h" #import <CoreLocation/CLAvailability.h> @implementation GeoCoding +(CLLocation*)findAddressCordinates:(NSString*)addressString { CLLocation *location; NSString *url = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true", addressString]; url = [url stringByReplacingOccurrencesOfString:@" " withString:@"%20"]; NSURL *wurl = [NSURL URLWithString:url]; NSData *data = [NSData dataWithContentsOfURL: wurl]; // Fail to get data from server if (nil == data) { NSLog(@"Error: Fail to get data"); } else{ // Parse the json data NSError *error; NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; // Check status of result NSString *resultStatus = [json valueForKey:@"status"]; // If responce is valid if ( (nil == error) && [resultStatus isEqualToString:@"OK"] ) { NSDictionary *locationDict=[json objectForKey:@"results"] ; NSArray *temp_array=[locationDict valueForKey:@"geometry"]; NSArray *temp_array2=[temp_array valueForKey:@"location"]; NSEnumerator *enumerator = [temp_array2 objectEnumerator]; id object; while ((object = [enumerator nextObject])) { double latitude=[[object valueForKey:@"lat"] doubleValue]; double longitude=[[object valueForKey:@"lng"] doubleValue]; location=[[CLLocation alloc] initWithLatitude:latitude longitude:longitude]; NSLog(@"CLLocation lat is %f -------------& long %f",location.coordinate.latitude, location.coordinate.longitude); } } } return location; } @end 

然后,您可以在Google地图中使用此坐标来聚焦相机位置。