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 に答える