2017-01-23 29 views
0

我嘗試網絡和GPs提供商的基礎代碼,以獲得設備的完美位置,但總是存在經度和緯度的不準確。我使用http://www.vogella.com/tutorials/AndroidLocationAPI/article.html來獲得值,得到緯度爲19.10295898和lon爲72.8866532。由谷歌地圖它是緯度,lon是19.103114,72.8867978。有區別。我們能否以某種方式真正匹配它。使用代碼如下:獲取緯度和日誌的實際位置沒有谷歌地圖

package jss.fusedlocation; 

import android.app.Activity; 
import android.content.Context; 
import android.location.Criteria; 
import android.location.Location; 
import android.location.LocationListener; 
import android.location.LocationManager; 
import android.os.Bundle; 
import android.widget.TextView; 
import android.widget.Toast; 

import com.google.android.gms.nearby.messages.Distance; 

/** 
* Created by DELL WORLD on 1/23/2017. 
*/ 

public class ShowLocationActivity extends Activity implements LocationListener { 
    private TextView latituteField; 
    private TextView longitudeField; 
    private LocationManager locationManager; 
    private String provider; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 
     latituteField = (TextView) findViewById(R.id.TextView02); 
     longitudeField = (TextView) findViewById(R.id.TextView04); 

     // Get the location manager 
     locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); 
     // Define the criteria how to select the locatioin provider -> use 
     // default 
     Criteria criteria = new Criteria(); 
     provider = locationManager.getBestProvider(criteria, false); 
     Location location = locationManager.getLastKnownLocation(provider); 
     location.setAccuracy(1); 

     // Initialize the location fields 
     if (location != null) { 
      System.out.println("Provider " + provider + " has been selected."); 
      onLocationChanged(location); 
     } else { 
      latituteField.setText("Location not available"); 
      longitudeField.setText("Location not available"); 
     } 
    } 

    /* Request updates at startup */ 
    @Override 
    protected void onResume() { 
     super.onResume(); 
     locationManager.requestLocationUpdates(provider, 1, 1, this); 
    } 

    /* Remove the locationlistener updates when Activity is paused */ 
    @Override 
    protected void onPause() { 
     super.onPause(); 
     locationManager.removeUpdates(this); 
    } 

    @Override 
    public void onLocationChanged(Location location) { 
     double lat = (double) (location.getLatitude()); 
     double lng = (double) (location.getLongitude()); 
     latituteField.setText(String.valueOf(lat)); 
     longitudeField.setText(String.valueOf(lng)); 
    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
     // TODO Auto-generated method stub 

    } 

    @Override 
    public void onProviderEnabled(String provider) { 
     Toast.makeText(this, "Enabled new provider " + provider, 
       Toast.LENGTH_SHORT).show(); 

    } 

    @Override 
    public void onProviderDisabled(String provider) { 
     Toast.makeText(this, "Disabled provider " + provider, 
       Toast.LENGTH_SHORT).show(); 
    } 
} 

回答

1

我試圖基於網絡和GPS提供商的代碼來獲得完美的位置,其中的裝置是

在一般情況下,這是不可能的「,以獲得完美的位置,其中設備是「,無論如何。獲取位置涉及許多變量,並非所有變量都會對您有利。

我們能不能匹配它在某種程度上

據我們所知,谷歌地圖使用的Play服務SDK的fused location provider

相關問題