Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

maps api2 animateCamera speed problems

I am trying to learn android, and playing with an app using the new googlemaps v2 api.

I have a couple of menu items, one zooms to current location, one will eventually zoom to another location. The first one (show_horizon in code bellow) enables the map to rotate, the second sets the map to static with north at the top of the screen.

I have set them both to have long 6 second delays, but the show_horizon() seems to ignore the speed setting, while the show_iss() respects it.

also, once in the rotate mode, if I scroll about the map, and the trigger show_horizon() it will now respect the speed setting.

So it seems to only ignore the code when I switch from non-rotating to rotating, but it respects it when I go the other way. I have tried stopping the listener when switching in case it was interrupting the camera animation, but it has made no difference?

Any clues or ideas welcome.

thanks

Here is the code.

I have a sensor listener getting the bearing of the phone like this:

private SensorEventListener get_bearing = new SensorEventListener() {
    @Override
    public void onAccuracyChanged(Sensor sensor, int accuracy) {
    }
    @Override
    public void onSensorChanged(SensorEvent event) {
      float azimuth = event.values[0];
      set_bearing(azimuth);
    }
  }; 

private void set_bearing(float azimuth) {
    if (!rotate_view) {
        bearing = 0;
    } else {
        if (bearing != Math.round(azimuth)) {
            bearing = Math.round(azimuth);
            update_map();
        }
    }
}

and couple of methods for changing the maps to rotating or not:

private void show_horizon() {
    current_pos = new LatLng(gps.getLatitude(), gps.getLongitude());
    rotate_view = true;
    tilt = 30;
    zoom_level = 14;
    stop_listener();
    update_map(6000);
    start_listener();
}

private void show_iss() {
    rotate_view = false;
    bearing = 0;
    tilt = 0;
update_map(6000);       
}

and my code to update the camera position:

private void update_map() {update_map(100);}   
private void update_map(int speed) {
    if (current_pos != null) {
        CameraPosition cameraPosition = new CameraPosition.Builder()
        .target(current_pos)      
        .zoom(zoom_level)               
        .bearing(bearing)                
        .tilt(tilt)                   
        .build();               
        gmap.animateCamera(CameraUpdateFactory.newCameraPosition(cameraPosition), speed, null);
    }
}
like image 312
Rob Avatar asked Dec 23 '12 20:12

Rob


1 Answers

This worked for me, after much trial and error:

 public void openMarker(Marker marker) {

    marker.showInfoWindow();
    CameraUpdate center = CameraUpdateFactory.newLatLng(marker.getPosition());
    mMap.animateCamera(center, 400, null);
}

mMap is my Google map object, of course.

mMap = ((SupportMapFragment)(getFragmentManager().findFragmentById(R.id.googleMap))).ge‌​tMap();
like image 118
TrippinBilly Avatar answered Nov 12 '22 11:11

TrippinBilly