问题描述
建立一个算法来找到一个由四组lat长度构成的多边形...并且通过当前lat来查找一组lat长是否属于那个多边形。但目前的经纬度并不准确。在android中使用GPS和网络系统来跟踪当前的经纬度。
public void find current_lat_long(){
com .example.gps.AppLocationService appLocationService = new com.example.gps.AppLocationService(
Map_Location.this);
位置gpsLocation = appLocationService
.getLocation(LocationManager.GPS_PROVIDER);
位置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;
字符串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;
返回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;
返回true;
}
}
请帮助找到准确的经纬度,以便跟踪长期属于特定多边形的纬度。
您可以使用以下代码查找位置:
声明变量:
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();
$ b $ 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;
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.
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;
这篇关于想用GPS经纬度建立考勤跟踪系统的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!