How to combine individual parts of address within a place dictionary for
geocoding?
At the moment, I have a place dictionary that contains values for all the
different parts of a typical address, that I then pass through a geocoder.
It looks like this:
[self.placeDictionary setValue:@"166 Bovet Rd" forKey:@"Street"];
[self.placeDictionary setValue:@"San Mateo" forKey:@"City"];
[self.placeDictionary setValue:@"CA" forKey:@"State"];
[self.placeDictionary setValue:@"94402" forKey:@"ZIP"];
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressDictionary:self.placeDictionary
completionHandler:^(NSArray *placemarks, NSError *error) {
if([placemarks count]) {
CLPlacemark *placemark = [placemarks objectAtIndex:0];
CLLocation *location = placemark.location;
CLLocationCoordinate2D coordinate = location.coordinate;
PFGeoPoint* userLocation = [PFGeoPoint
geoPointWithLatitude:coordinate.latitude
longitude:coordinate.longitude];
NSLog(@"%f,%f", userLocation.latitude, userLocation.longitude);
} else {
NSLog(@"location error");
return;
}
}];
Instead of having a separate dictionary entry for each individual part of
the address, could I merge them into one string to pass through the
geocoder? Something of this effect:
[self.placeDictionary setValue:@"166 Bovet Rd San Mateo CA 94402"
forKey:@"Address"];
The reason I want to do this is I have a search bar in which a user is
supposed to enter a location into for geocoding, and I can't divide it and
extract each individual part of the address, so is there a way that I can
pass the entire address like so, for geocoding?
No comments:
Post a Comment