0

I am working with Google Maps V2 and i want that the blue arrow is always centered on the map when i was driving/moving. But it remains for a 3-4 seconds on the spot and then jumps suddenly to the center. If i drive fast, the arrow is even in the few seconds out of the map and jumps then to the center. What i am doing wrong in the code?

public class MainActivity extends FragmentActivity implements LocationListener {
....

//when button is clicked
public void initStart() {
    initMap();
    initLocation();
}

 public void initMap() {
    supportmapfragment = (SupportMapFragment)getSupportFragmentManager().findFragmentById(R.id.googleMap);

    myMap = supportmapfragment.getMap();
    myMap.setMapType(GoogleMap.MAP_TYPE_NORMAL);
    myMap.setMyLocationEnabled(true);
    myMap.getUiSettings().setAllGesturesEnabled(false);
    myMap.getUiSettings().setZoomControlsEnabled(false);
}


  public void initLocation() {
    lm = (LocationManager)getSystemService(LOCATION_SERVICE);
    provider = LocationManager.GPS_PROVIDER;

    Location location = lm.getLastKnownLocation(provider);

    if(provider != null ) {
        onLocationChanged(location);
    }
    lm.requestLocationUpdates(provider, 0, 0, this);  
}

  ....

  @Override
public void onLocationChanged(Location location) {

 if(location != null) {

 LatLng latLng = new LatLng(location.getLatitude(), location.getLongitude());
 myMap.moveCamera(CameraUpdateFactory.newLatLngZoom(latLng, 17));
 }
}

Does anyone have a counsel? thanks in advance

PS: sry for my english (its not good) :)

KenMasters
  • 401
  • 3
  • 8
  • 19
  • 1
    Have a look at this answer here http://stackoverflow.com/a/14305851/2045570 – nedaRM Jul 12 '13 at 06:52
  • yes, but that is the new api or not?? i am not using the new api yet. i have to work it with the older api. my problem is only the marker/arrow by driving, to hold it in the center of the map. – KenMasters Jul 12 '13 at 08:24

1 Answers1

0

Instead of LocationManager use GoogleMap.setOnMyLocationChangeListener, which notifies you when the position of blue dot is changed.

MaciejGórski
  • 22,187
  • 7
  • 70
  • 94
  • Hi Maciej, so I should not use the locationmanager?? can you tell me how and where exactly should I use the GoogleMap.setOnMyLocationChangeListener? I'm honestly a little confused. – KenMasters Jul 12 '13 at 14:13