gpt4 book ai didi

ios - 正向地理编码没有给出正确的结果

转载 作者:行者123 更新时间:2023-11-29 10:28:41 24 4
gpt4 key购买 nike

在某些情况下,我没有得到正向地理编码的正确结果。当我搜索某些地方或酒店时,它会显示其他一些地方或地区的结果。我有以下代码。我研究以下link .我应该放置什么网址才能获得正确的结果。

我们如何实现以下网站中给出的内容

https://developers.google.com/places/webservice/autocomplete

A request for addresses containing "Vict" with results in French:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=geocode&language=fr&key=API_KEY A request for cities containing "Vict" with results in Brazilian Portuguese:

https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Vict&types=(cities)&language=pt_BR&key=API_KEY

我已经实现了以下但它没有给出我方面的结果

- (CLLocationCoordinate2D)addressLocation{
NSError *error = nil;

// NSString *lookUpString = [NSString stringWithFormat:@"http://maps.googleapis.com/maps/api/geocode/json?address=%@&sensor=true", SearchtextField];
// NSString *API_KEY=@"AIzaSyB27SkGBzvEYKcxvZ5nmOVWvrA-6Xqf-7A";
NSString *API_KEY=@"AIzaSyCHcqJcqZbP1XpU-WB4VfRct5hpdgqisSY";
NSString *lookUpString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/geocode/json?address=%@&region=np&key=%@", SearchtextField,API_KEY];



lookUpString = [lookUpString stringByReplacingOccurrencesOfString:@" " withString:@"+"];

NSData *jsonResponse = [NSData dataWithContentsOfURL:[NSURL URLWithString:lookUpString]];

NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:jsonResponse options:kNilOptions error:&error];
NSArray *locationArray = [[[jsonDict valueForKey:@"results"] valueForKey:@"geometry"] valueForKey:@"location"];


NSString *statusString = [jsonDict valueForKey:@"status"];

if ([statusString isEqualToString:@"OK"])
{
locationArray = [locationArray objectAtIndex:0];

Str_Latitude= [locationArray valueForKey:@"lat"];
Str_Longitude= [locationArray valueForKey:@"lng"];

NSLog(@"LatitudeString:%@ & LongitudeString:%@", Str_Latitude, Str_Longitude);
/*Google place latitude Longitude*/
Arr_LatLong = @[Str_Latitude,Str_Longitude];

[[NSUserDefaults standardUserDefaults] setValue:Str_Latitude forKey:@"Str_Latitude"];
[[NSUserDefaults standardUserDefaults] setValue:Str_Longitude forKey:@"Str_Longitude"];
[[NSUserDefaults standardUserDefaults] synchronize];

GogLatitude = [Str_Latitude doubleValue];
Goglongitude = [Str_Longitude doubleValue];

if (Bool_SearchField) {
[self getGoogleAddress];
Bool_SearchField=FALSE;
}else{

}


}else{

UIAlertView *alertview =[[UIAlertView alloc] initWithTitle:@"Address not found" message:@"make sure you enter a valid address" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alertview show];

NSLog(@"Something went wrong, couldn't find address");
[self.tableView reloadData];
}

GogLocation.latitude = GogLatitude;
GogLocation.longitude = Goglongitude;

return GogLocation;
}

When i search for radission in maps.google.com it shows as below

enter image description here

But when i search in my app it shows different locations then what I search enter image description here

最佳答案

您可以使用 Region Biasing ,这according to wiki , 应该是 NP。因此,请在查询末尾添加 &region=np

或者您可以使用 Viewport Biasing设置搜索范围。

关于ios - 正向地理编码没有给出正确的结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30842086/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com