GPS纬度,经度

时间:2012-08-09 09:10:29

标签: android google-maps gps maps

我有GPS代码用于查找纬度,经度。 TouchEvent非常有用。在地图应用程序而不是TouchEvent上显示纬度,经度的任何其他方式吗?

2 个答案:

答案 0 :(得分:1)

我认为它应该对你非常有用

http://www.bogotobogo.com/Android/android17MapView.php

答案 1 :(得分:1)

你好检查一下这是否对你有帮助:)

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    LocationManager locationManager;
    locationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
    Location location =locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
    updateWithNewLocation(location);
}
private void updateWithNewLocation(Location location) {
    String latLongString = "Unknown";
    String addressString = "No address found";
    TextView myLocationText;
    DecimalFormat df = new DecimalFormat("##.00");  
    myLocationText = (TextView)findViewById(R.id.myLocationText);
    if (location != null) {
        double lat = location.getLatitude();
        double lng = location.getLongitude();
        latLongString = "Lat:" +  df.format(lat) + "\nLong:" +  df.format(lng);
        Geocoder gc = new Geocoder(GPS1Activity.this, Locale.getDefault());
        try {
            List<Address> addresses  = gc.getFromLocation(lat, lng, 1);
            if (addresses.size() == 1) {
                addressString="";
                Address address = addresses.get(0);
                addressString = addressString + address.getAddressLine(0) + "\n";
                for (int i = 0; i < address.getMaxAddressLineIndex(); i++){
                    addressString = addressString + address.getAddressLine(i) + "\n";
                }
                addressString = addressString + address.getLocality()+ "\n";
                addressString = addressString + address.getPostalCode()+ "\n";
                addressString = addressString + address.getCountryName()+ "\n";
            }
        } catch (IOException ioe) {
            Log.e("Geocoder IOException exception: ", ioe.getMessage());
        }
    }       
    myLocationText.setText("Your Current Position is:\n" + latLongString + "\n" + addressString);
}