-2

这是我的代码,它加载了 normali,但是当我更改纬度和经度时,它不显示相应的位置。我使用模拟器来测试程序。我通过使用模拟器控制更改纬度和经度。

package com.rumes.gspuse;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;

import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

public class Main extends MapActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        MapView map=(MapView) findViewById(R.id.map);

        map.setBuiltInZoomControls(true);

        final MapController controller=map.getController();
        LocationManager manager=(LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
        LocationListener listner=new LocationListener() {

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

            }

            @Override
            public void onProviderEnabled(String provider) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onProviderDisabled(String provider) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onLocationChanged(Location location) {
                controller.setCenter(new GeoPoint((int)location.getLatitude(), (int)location.getLongitude()));

            }
        };

        manager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,listner);
    }

    @Override
    protected boolean isRouteDisplayed() {
        // TODO Auto-generated method stub
        return false;
    }
}
4

1 回答 1

1

您需要 latitudeE6 和 longitudeE6,这就是为什么您在地图上看不到任何差异的原因!

if(location != null) // avoid crash (check for null)..
    controller.setCenter(new GeoPoint((int)(location.getLatitude() * 1E6), (int)(location.getLongitude() * 1E6)));
于 2012-11-28T16:00:34.397 回答