【问题标题】:how to get current position?如何获得当前位置?
【发布时间】:2011-04-21 06:36:04
【问题描述】:

我已经获得了这个地址,并告诉我找到我的当前位置

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

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

请帮忙

【问题讨论】:

    标签: iphone api geolocation


    【解决方案1】:

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

    【讨论】:

      【解决方案2】:

      602,0,0,0

      这是您的位置坐标。根据谷歌地图,你位于这里

      【讨论】:

      • 你怎么知道 OP 的位置? :)
      • 没有人在地址位置输入您的地址并以 csv 格式写入您想要的结果格式,如 json 等。
      • OP = 原始海报 = rajesh
      【解决方案3】:

      通过它您可以获得地址的纬度和经度。如果您请求此 url 并使用要查找坐标的地址,您将获得 4 值作为响应。你可以使用这个函数来获取一个带有 lat 和 log 的 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

      【讨论】:

      • 这是 json 格式的经纬度 "Point": { "coordinates": [ -119.9590257, 36.2552300, 0 ] }
      • 反正 36.2552300 是纬度,-119.9590257 是经度。在 gmaps 中:maps.google.com/…
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多