Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to move the Android Google Maps API Compass Position

Tags:

Does anyone know if you can change the compass position within the map?

All I can find is how to enable or disable it. But I need to move it down a bit so my overlay is not obstructing it.

enter image description here

like image 789
capdragon Avatar asked Feb 23 '13 16:02

capdragon


People also ask

How do I change the compass on Google Maps Android?

Open the Google Maps app, making sure that your blue circular device location icon is in view. Tap on the location icon to bring up more information about your location. At the bottom, tap the “Calibrate Compass” button. This will bring up the compass calibration screen.

How do I get the compass direction on Google Maps?

The compass appears as a widget on the right-hand side of the map screen, with a red arrow determinedly pointing north on the map as you rotate your phone.

How do I drag a marker on Google Maps Android?

Long press the marker to enable dragging. When you take your finger off the screen, the marker will remain in that position. Markers are not draggable by default. You must explicitly set the marker to be draggable either with MarkerOptions.

Does Google Maps on Android have a compass?

Where to Find the Compass in Google Maps for Android. If you are running Google Maps 10.62 or a newer build on your Android device, you should see the compass widget in the Navigation screen right below the volume button. The compass widget will only show up when using navigation in Google Maps.


2 Answers

Use GoogleMap.setPadding() method:

https://developers.google.com/maps/documentation/android/map#map_padding

like image 84
Benjamin Ting Avatar answered Sep 22 '22 22:09

Benjamin Ting


@Override public void onMapReady(GoogleMap map) {      try {         final ViewGroup parent = (ViewGroup) mMapView.findViewWithTag("GoogleMapMyLocationButton").getParent();         parent.post(new Runnable() {             @Override             public void run() {                 try {                     Resources r = getResources();                     //convert our dp margin into pixels                     int marginPixels = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20, r.getDisplayMetrics());                     // Get the map compass view                     View mapCompass = parent.getChildAt(4);                      // create layoutParams, giving it our wanted width and height(important, by default the width is "match parent")                     RelativeLayout.LayoutParams rlp = new RelativeLayout.LayoutParams(mapCompass.getHeight(),mapCompass.getHeight());                     // position on top right                     rlp.addRule(RelativeLayout.ALIGN_PARENT_LEFT, 0);                     rlp.addRule(RelativeLayout.ALIGN_PARENT_TOP);                     rlp.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);                     rlp.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, 0);                     //give compass margin                     rlp.setMargins(marginPixels, marginPixels, marginPixels, marginPixels);                     mapCompass.setLayoutParams(rlp);                 } catch (Exception ex) {                     ex.printStackTrace();                 }             }         });     } catch (Exception ex) {         ex.printStackTrace();     }  } 
like image 24
Vignon Avatar answered Sep 25 '22 22:09

Vignon