I am trying to learn Android and play with the app using the new googlemaps v2 api.
I have a couple of menu items, one scaled to the current location, and ultimately it will increase to another location. The first (show_horizon in the code below) allows the card to rotate, and the second puts the card on a static one from the north at the top of the screen.
I set them as long 6 second delays, but show_horizon () seems to ignore the speed setting, while show_iss () respects it.
also, once in rotation mode, if I scroll the map, and the show_horizon () trigger will now comply with the speed setting.
That way, he simply ignores the code when I switch from non-rotating to spin, but he respects it when I go the other way. I tried to stop the listener when switching, if he interrupted the camera animation, but it didnβt matter?
Any hints or ideas are welcome.
thanks
Here is the code.
I have a sensor listener that gets the phone mount as follows:
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 several ways to change cards to rotation 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); } }