开发者

how to get current position?

开发者 https://www.devze.com 2023-02-27 06:34 出处:网络
I have been provided with this address and told to find th开发者_如何学运维e current location of me

I have been provided with this address and told to find th开发者_如何学运维e current location of me

http://maps.google.com/maps/geo?q=address&output=csv

what kind of address is this and how can i get the information about this . Is this API ?

Please help


suppose if you give http://maps.google.com/maps/geo?q=newyork&output=csv, the result will be 200,4,40.7143528,-74.0059731.The last 2 values mean latitude and longitude value for New york...I hope it will help you.If you integrate this url in your app, you can get co-ordinates and use them to show the map in MKMapView in iPhone.


602,0,0,0

this is your location coordinates. and according to Google map you are located

how to get current position?

here


With that you can get latitude and longitude of an address. If you request this url and you use the address you want to find the coordinates you get 4 value as a response. You can use this function to get a Location object with lat and log of your address:

-(CLLocationCoordinate2D) addressLocation:(NSString *)address {
  NSString *urlString = [NSString stringWithFormat:@"http://maps.google.com/maps/geo?q=%@&output=csv", 
                [address stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
  NSString *locationString = [NSString stringWithContentsOfURL:[NSURL URLWithString:urlString]];
  NSArray *listItems = [locationString componentsSeparatedByString:@","];

  double latitude = 0.0;
  double longitude = 0.0;

  if([listItems count] >= 4 && [[listItems objectAtIndex:0] isEqualToString:@"200"]) {
    latitude = [[listItems objectAtIndex:2] doubleValue];
    longitude = [[listItems objectAtIndex:3] doubleValue];
  }
  else {
     //Show error
  }
  CLLocationCoordinate2D location;
  location.latitude = latitude;
  location.longitude = longitude;

  return location;
}

You can find more help here: http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial

0

精彩评论

暂无评论...
验证码 换一张
取 消