开发者

Problem with locationListener

The application doesnt point to where I am at..here is what i have done:

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

    mv=(MapView) findViewById (R.id.mapView);
    mv.setBuiltInZoomControls(true);
   // mv.setSatellite(true);
    mv.setStreetView(true);


lmanager=(LocationManager)getSystemService(Context.LOCATION_SERVICE);
    ll开发者_开发知识库istener=new MyLocationListener();
    lmanager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, llistener);

}

private class MyLocationListener implements LocationListener
{

    @Override
    public void onLocationChanged(Location location) {
        // TODO Auto-generated method stub
        if(location!=null)
        {
            Toast.makeText(getBaseContext(),"Location changed: "+location.getLatitude()+" lang: "+ location.getLongitude() , Toast.LENGTH_SHORT).show(); // no toast is shown
        }
         p=new GeoPoint((int)(location.getLatitude()*1E6), (int)(location.getLongitude()*1E6));
        mapC.animateTo(p);
        mapC.setZoom(18);//no zooming happens
    }



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

    }

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

    }

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

    }

To my manifest I added both of these:

    <uses-permission android:name="android.permission.INTERNET"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>


first of all sorry for poor english. when the location was changed and you set the value into the map you need to invalidate the map using the invalidate() method of MapView class so you can get the updated value on the map

mapC.animateTo(p);
mapC.setZoom(18);
mv.invalidate();

as well as add after you set the value at initial time set into the map like

mv.setBuiltInZoomControls(true);
mv.setStreetView(true);
mv.invalidate();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜