Posted By

mlecho on 04/24/11


Tagged

mapping geo


Versions (?)

CLLocationCoordiante2D from address string


 / Published in: Objective C
 

  1. -(CLLocationCoordinate2D) addressLocation:(NSString *)input {
  2. NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv",
  3. [input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  4. NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
  5. NSArray *listItems = [locationString componentsSeparatedByString:@","];
  6.  
  7. double latitude = 0.0;
  8. double longitude = 0.0;
  9.  
  10. if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
  11. latitude = [[listItems objectAtIndex:2] doubleValue];
  12. longitude = [[listItems objectAtIndex:3] doubleValue];
  13. }
  14. else {
  15. //Show error
  16. }
  17. CLLocationCoordinate2D location;
  18. location.latitude = latitude;
  19. location.longitude = longitude;
  20. return location;
  21. }
  22.  

Report this snippet  

You need to login to post a comment.