Want to build attendance tracking system with GPS latitude and longitude

∥☆過路亽.° 提交于 2019-12-12 02:07:10

问题


build a algorithm to find a polygon build by four sets of lat long.. and passing current lat long to find whether a set of lat long belong to that polygon or not. But the the current latiitude and longitude is not accurate . in android using GPS and network system to tracking current latitude and longitude.

 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;


    } 

}

Please help to find accurate lat long to tracking that lat long belong to the particular polygon.


回答1:


You can find location using the below code:

Declare the variable:

LocationManager lm;
LocationListener ll;

Start Location listener :

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

Location listener:

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) {
    }

}

After finding location you can stop listener using this in onLocationChanged:

 lm.removeUpdates(ll);
 lm = null;


来源:https://stackoverflow.com/questions/27119183/want-to-build-attendance-tracking-system-with-gps-latitude-and-longitude

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!