I didn't get correct results for Forward geocoding in certain cases. When I search for some places or hotel it shows result of some others places or areas. I have got following code. I study the following link. What url should i place to get correct results.
how can we implement the following given in following site
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:
I have implemented following but it doesn't give the results as i aspected
- (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=%@®ion=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
But when i search in my app it shows different locations then what I search
You can either take use of the Region Biasing, which according to wiki, should be
NP
. So add®ion=np
at the end of your query.Or you can use the Viewport Biasing to set the bounds of your searches.