iPhone&iPod Touch定位编写

1. 使用UIMapView的showUserLocation属性。

    myMapView.showsUserLocation = YES
    显示后读出坐标经纬度:
     self.userLocation.coordinate.latitude
   self.userLocation.coordinate.longitude

2. 使用CLLocationManager

     locationManager = [[CLLocationManager alloc] init];
   locationManager.delegate = self;
   locationManager.desiredAccuracy = kCLLocationAccuracyBest; //选择最优定位
   [locationManager startUpdatingLocation];

    定位后在委托方法中读出经纬度:

- (void)locationManager:(CLLocationManager *)manager
    didUpdateToLocation:(CLLocation *)newLocation
           fromLocation:(CLLocation *)oldLocation

前两种方法是利用Core Location框架来定位,按照GPS,蜂窝基站(Cell Tower),Wi-Fi的顺序选取最后方案定位:

    a.  GPS定位:精确度可以高达10m;
    b.  蜂窝基站:精确度与当地基站的密度有关;
    c.  Wi-Fi:利用IP地址定位,不精确,有时会有数英里的误差。iPhone的Wi-Fi定位使用Skyhook Wireless来返回相应IP地址的的地理坐标。由于公司的IP没有包含在库中,所以无法使用iPhone自带的Wi-Fi定位;


3. 使用FireFox和Safari的定位服务:

    写一个html,用MapVIew加载,用alert返回获得的地理坐标信息。
<html>
<head>
<title> Know your current location </title>
<script type="text/javascript" src="json2.js"></script>
<script type="text/javascript">
  navigator.geolocation.getCurrentPosition(getLocation, unknownLocation);
 
  function getLocation(pos)
  {
    var latitde = pos.coords.latitude;
    var longitude = pos.coords.longitude;
    alert(JSON.stringify({"latitude":latitde,
                          "longtitude":longitude}));
  }
  function unknownLocation()
  {
    alert('Could not find location');
  }
</script>
</head>
</html>

    这种方法可以实现Wi-Fi定位,但是不精确。
原文地址:https://www.cnblogs.com/mac_arthur/p/1708334.html