如何获得当前位置?

时间:2011-04-21 06:36:05

标签: iphone api geolocation

我已获得此地址并被告知要查找我当前的位置

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

这是什么类型的地址,我如何获得有关此信息。这是API吗?

请帮忙

3 个答案:

答案 0 :(得分:2)

假设您提供http://maps.google.com/maps/geo?q=newyork&output=csv,结果将是 200,4,40.7143528,-74.0059731。最后2个值表示纽约的纬度和经度值...我希望它能帮助你。如果你在你的应用程序中集成这个url,你可以得到坐标并使用它们来在iPhone中的MKMapView中显示地图。

答案 1 :(得分:0)

602,0,0,0

这是您的位置坐标。根据Google地图,您位于此处enter image description here

答案 2 :(得分:0)

通过它,您可以获得地址的纬度和经度。如果您请求此网址并使用您想要查找坐标的地址,则会获得4个值作为响应。您可以使用此函数来获取带有lat和地址日志的Location对象:

-(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;
}

您可以在此处找到更多帮助:http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial