问题
I have an app which prompts the user to input an address. Is there a way to check whether or not the address is a valid address, either using Google's Maps or Places APIs or not? Any help would be appreciated. I know it's a vague question but I'm not really sure how to ask it any other way.
回答1:
A fast way to kill 95% spam profiles was for my company to have a onboard list of us state names and zip codes. If zip code and state did not match, we peomted the user to check again.
Not foolproof at all, but if spammers are the problem, this might help.
回答2:
NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
[addressField.text stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; // addressField is where you enter your address.
NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString] encoding:NSUTF8StringEncoding error:nil];
NSArray *listItems = [locationString componentsSeparatedByString:@","];
if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
latitude = [[listItems objectAtIndex:2] doubleValue];
longitude = [[listItems objectAtIndex:3] doubleValue];
If address exists you will get coordinates in latitude and longitude. Hope this helps.
来源:https://stackoverflow.com/questions/6863992/check-validity-of-address-with-geocoding-on-iphone