Check validity of address with Geocoding on iPhone

只愿长相守 提交于 2019-12-11 07:42:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!