0

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

4

2 回答 2

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);
}
于 2012-08-09T09:15:28.690 回答
0

我认为它应该对你很有用

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

于 2012-08-09T09:13:58.537 回答