2014-11-25 50 views
0

建立一个算法,通过四组lat长度来寻找一个多边形...并且通过当前经纬度来查找一组lat长度是否属于该多边形。但目前的经纬度并不准确。在android中使用GPS和网络系统来跟踪当前的经纬度。想用GPS经纬度建立考勤跟踪系统

public void find current_lat_long(){ 
com.example.gps.AppLocationService appLocationService = new com.example.gps.AppLocationService(
      Map_Location.this); 
    Location gpsLocation = appLocationService 
      .getLocation(LocationManager.GPS_PROVIDER); 
    Location nwLocation = appLocationService 
      .getLocation(LocationManager.NETWORK_PROVIDER); 
    if (gpsLocation != null) { 
     latitude_gps_calc_lat = gpsLocation.getLatitude(); 
     longitude_gpa_calc_lng = gpsLocation.getLongitude(); 
     constant.lat=String.valueOf(gpsLocation.getLatitude()); 
     constant.longitude=String.valueOf(gpsLocation.getLongitude()); 
     constant.flag_gps=false; 
     String latlong_gps = String.valueOf(gpsLocation.getLatitude())+String.valueOf(gpsLocation.getLongitude()); 
//  lat1_string=constant.lat; 
//   long_1_string=constant.longitude; 

      lat4_string=constant.lat; 
      long_4_string=constant.longitude; 

     return true; 
    } 
    else if (nwLocation != null) 
     { 
       latitude_network_provider = nwLocation.getLatitude(); 
       longitude_network_provider = nwLocation.getLongitude(); 
       constant.flag_network=false; 
       latlong__network_provider =String.valueOf(latitude_network_provider)+String.valueOf(longitude_network_provider); 

       constant.lat=String.valueOf(latitude_network_provider); 
       constant.longitude=String.valueOf(longitude_network_provider); 
        lat4.setText(constant.lat+constant.longitude); 
        lat4_string=constant.lat; 
        long_4_string=constant.longitude; 

      return true; 


    } 

}

请帮忙找准确的经纬度长时间追踪Lat Long网属于特定的多边形。

+0

那你到底要?请说明你的需求 – 2014-11-25 05:47:11

+0

你想找到那些经纬度长点吗?或者检查一个新点是否属于这个多边形? – 2014-11-25 05:49:39

+0

只是模糊了你想要做什么的图片,请** **点**你的要求,或编码怀疑等 – nobalG 2014-11-25 05:54:36

回答

0

您可以使用下面的代码中找到的位置:

声明变量:

LocationManager lm; 
LocationListener ll; 

开始位置监听器:

lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); 
    ll = new startLocationListener(); 
    lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,ll); 

位置监听器:

class gpsLocationListener implements LocationListener { 

    public void onLocationChanged(Location location) { 
     if (location != null) { 
      String latitude = location.getLatitude(); 
      String longitude = location.getLongitude();     
     } 
    } 

    public void onProviderDisabled(String provider) { 
    } 

    public void onProviderEnabled(String provider) { 
    } 

    public void onStatusChanged(String provider, int status, Bundle extras) { 
    } 

} 

找到位置后,您可以在onLocationChanged使用该停止监听器:

lm.removeUpdates(ll); 
lm = null; 
+0

根本不工作。没有返回正确和准确的结果... – 2014-11-25 08:43:58

+0

它正在工作中,你可以使用这个得到lat。你在哪里叫这个?调用此侦听器将为您提供准确的位置,在侦听器的onLocationChanged方法中。 – 2014-11-25 08:51:40

+0

你知道它不工作的意义,当我从一个地方移动到另一个它返回相同的经纬度,当我想设置四个纬度长点,我改变了我的位置,但位置监听器没有相应更新 – 2014-11-25 09:05:05