1)我的android應用程序需要計算用戶按下開始時的累積距離。當我跑步時,它等一會兒然後開始計算。我認爲這可能是好的。但是當我不動的時候,米也是自己積累的。 當我在外面移動時測試它時,藍點不準確並且一直在跳。這會使距離不準確。現在我重新測試,我認爲紅色標記是我的,因爲它顯示「你在這裏」,有一次我測試了它。它遍佈各處。我如何提高GPS精度。 從看起來來看,儀表不準確性是由於gps跳動而不是計算。我想做一個點跟着我,並沒有多少標記出現在我已經..android在谷歌地圖上的不準確的GPS地圖v2
2)此外,我試圖顯示此模擬器上,但失敗(谷歌地圖V2)。我確實用新創建的模擬器安裝了一些apk,但也失敗了。即使它有效也是非法的嗎?我也需要和我的團隊一樣在相同的模擬器上顯示。作爲我可以在手機上顯示的最後一招。
3)使谷歌地圖V2在其他電腦上工作我需要做什麼。我的研究表明我需要簽署API密鑰,但到目前爲止我發現是谷歌地圖v1版本。
我的Java文件
public class MainActivity extends FragmentActivity implements LocationListener{
protected LocationManager locationManager;
private GoogleMap googleMap;
Button btnStartMove,btnPause,btnResume,btnStop;
static double n=0;
Long s1,r1;
double dis=0.0;
Thread t1;
EditText userNumberInput;
boolean bool=false;
int count=0;
double lat1,lon1,lat2,lon2,lat3,lon3,lat4,lon4;
double dist = 0;
TextView distanceText;
float[] result;
private static final long MINIMUM_DISTANCE_CHANGE_FOR_UPDATES = 0; // in Meters
private static final long MINIMUM_TIME_BETWEEN_UPDATES = 0;
boolean startDistance = false;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MINIMUM_TIME_BETWEEN_UPDATES,MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, this);
if(isGooglePlay())
{
setUpMapIfNeeded();
}
distanceText=(TextView)findViewById(R.id.Distance);
btnStartMove=(Button)findViewById(R.id.Start);//start moving
btnStartMove.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v) {
startDistance = true;
}
});
//prepare distance...........
Log.d("GPS Enabled", "GPS Enabled");
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
String provider = locationManager.getBestProvider(criteria, true);
Location location=locationManager.getLastKnownLocation(provider);
if(location!= null)
{
//Display current location in Toast
String message = String.format(
"Current Location \n Longitude: %1$s \n Latitude: %2$s",
location.getLongitude(), location.getLatitude()
);
Toast.makeText(MainActivity.this, message,
Toast.LENGTH_LONG).show();
//Display current location in textview
//latitude.setText("Current Latitude: " + String.valueOf(location.getLatitude()));
//longitude.setText("Current Longitude: " + String.valueOf(location.getLongitude()));
lat3 = location.getLatitude();
lon3 = location.getLongitude();
}
else if(location == null)
{
Toast.makeText(MainActivity.this,
"Location is null",
Toast.LENGTH_LONG).show();
}
}
private void setUpMapIfNeeded() {
if(googleMap == null)
{
Toast.makeText(MainActivity.this, "Getting map",
Toast.LENGTH_LONG).show();
googleMap =((SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.displayMap)).getMap();
if(googleMap != null)
{
setUpMap();
}
}
}
private void setUpMap()
{
//Enable MyLocation Layer of Google Map
googleMap.setMyLocationEnabled(true);
//Get locationManager object from System Service LOCATION_SERVICE
//LocationManager locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
//Create a criteria object to retrieve provider
Criteria criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_FINE);
//Get the name of the best provider
String provider = locationManager.getBestProvider(criteria, true);
if(provider == null)
{
onProviderDisabled(provider);
}
//set map type
googleMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
//Get current location
Location myLocation = locationManager.getLastKnownLocation(provider);
if(myLocation != null)
{
onLocationChanged(myLocation);
}
locationManager.requestLocationUpdates(provider, 0, 0, this);
}
private boolean isGooglePlay()
{
int status = GooglePlayServicesUtil.isGooglePlayServicesAvailable(this);
if (status == ConnectionResult.SUCCESS)
{
Toast.makeText(MainActivity.this, "Google Play Services is available",
Toast.LENGTH_LONG).show();
return(true);
}
else
{
GooglePlayServicesUtil.getErrorDialog(status, this, 10).show();
}
return (false);
}
@Override
public void onLocationChanged(Location myLocation) {
//show location on map.................
//Get latitude of the current location
double latitude = myLocation.getLatitude();
//Get longitude of the current location
double longitude = myLocation.getLongitude();
//Create a LatLng object for the current location
LatLng latLng = new LatLng(latitude, longitude);
//Show the current location in Google Map
googleMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
//Zoom in the Google Map
googleMap.animateCamera(CameraUpdateFactory.zoomTo(20));
googleMap.addMarker(new MarkerOptions().position(new LatLng(latitude, longitude)).title("You are here!"));
//show distance............................
if(startDistance == true)
{
Toast.makeText(MainActivity.this,
"Location has changed",
Toast.LENGTH_LONG).show();
if(myLocation != null)
{
//latitude.setText("Current Latitude: " + String.valueOf(loc2.getLatitude()));
//longitude.setText("Current Longitude: " + String.valueOf(loc2.getLongitude()));
float[] results = new float[1];
Location.distanceBetween(lat3, lon3, myLocation.getLatitude(), myLocation.getLongitude(), results);
System.out.println("Distance is: " + results[0]);
dist += results[0];
DecimalFormat df = new DecimalFormat("#.##"); // adjust this as appropriate
if(count==1)
{
distanceText.setText(df.format(dist) + "meters");
}
lat3=myLocation.getLatitude();
lon3=myLocation.getLongitude();
count=1;
}
}
}
@Override
public void onProviderDisabled(String provider) {
Toast.makeText(MainActivity.this,
"Provider disabled by the user. GPS turned off",
Toast.LENGTH_LONG).show();
}
@Override
public void onProviderEnabled(String provider) {
Toast.makeText(MainActivity.this,
"Provider enabled by the user. GPS turned on",
Toast.LENGTH_LONG).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
Toast.makeText(MainActivity.this, "Provider status changed",
Toast.LENGTH_LONG).show();
}
@Override
protected void onPause() {
super.onPause();
locationManager.removeUpdates(this);
}
@Override
protected void onResume() {
super.onResume();
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,MINIMUM_TIME_BETWEEN_UPDATES,MINIMUM_DISTANCE_CHANGE_FOR_UPDATES, this);
}}
第一截圖,以秒一段時間後第二,約1小時後三分之一。
在THRID拍攝,畫面隨時返回到那裏有許多紅色的標記,而不是藍點的地方。 「烤麪包改變了」繼續留在屏幕上
主要問題是通過確保準確的GPS確保準確的距離。我一直很困擾這一點,我甚至從我的應用程序中拿走了地圖,因爲我無法解決它,但現在我需要它。
location.getSpped()?我從來沒有在我的代碼中使用它。你的意思是我必須有一個速度門檻來實現,所以在一定的速度,然後我計算距離?有沒有特定的代碼/類?謝謝 – Myst
location.getSpeed()。一個位置不僅具有經度和緯度,還具有速度和航向,估計精度等。是的,你需要速度去除不可靠的GPS。還有其他的可能性,但這是一個簡單的方法,適用於所有比行走的人快得多的物體。 – AlexWien
不好意思打擾你,但是我可以找到很多例子。所以我創建一個雙倍速度= 5(這是M/S,所以我怎麼知道它是超過5公里/小時?),然後location.getSpeed(); >速度 - >做我的東西。但我在哪裏放置?在位置change.or開始或顯示位置? – Myst