0

I'm currently working on a mapview, and I want to display the user's position like the google's Latitude (compass direction); I saw several topic on that, but none of them give me the adequate solution for my query. Do you have a tutorial or examples to do this?

Kara
  • 6,115
  • 16
  • 50
  • 57
Ivory
  • 77
  • 1
  • 10

3 Answers3

1

Use MyLocationOverlay. Example code:

public MyMapActivity extends MapActivity {
  private MyLocationOverlay myLocationOverlay;
  private MapView mapView;

  @Override
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.my_map_layout);

    mapView = (MapView)findViewById(R.id.map_view);

    myLocationOverlay = new MyLocationOverlay(this, mapView);
    mapView.getOverlays().add(myLocationOverlay);
  }

  @Override
  protected void onResume() {
    super.onResume();

    myLocationOverlay.enableCompass();
    myLocationOverlay.enableMyLocation();
  }

  @Override
  protected void onPause() {
    super.onPause();

    myLocationOverlay.disableCompass();
    myLocationOverlay.disableMyLocation();
  }

  @Override
  protected boolean isRouteDisplayed() {
    return false;
  }
}
aromero
  • 25,681
  • 6
  • 57
  • 79
  • Yes, i already try this solution but, the position is a dot, and I want an arrow showing the direction of the compass, like the google's latitude – Ivory Jan 03 '12 at 13:23
  • :the showing position is a dot, but i want the arrow like the google's latitude app : you see what i mean ? like this : http://img.clubic.com/04058312-photo-google-maps-5-2-pour-android-ping.jpg – Ivory Jan 03 '12 at 13:49
  • There is nothing out of the box that looks like that. Best chance is to override MyLocationOverlay to draw the icon you like. – aromero Jan 03 '12 at 14:03
  • I tried that to, but the icon does not rotate properly. I use matrix.postRotate (bearing); before drawing. My icon is the compass direction every 5-10 seconds – Ivory Jan 03 '12 at 15:48
0

Just in case somebody is facing out this problem anymore. First of all, this needs both LocationListener and SensorEventListener. Here you can find more details of how to use it in this scope. Anyway, Android Google Maps V2 Api partially solves this problem, displaying an arrow indicating your orientation but only when the device is moving otherway a dot will be displayed.

Community
  • 1
  • 1
AlexAndro
  • 1,918
  • 2
  • 27
  • 53
0

May be this answer solves your problem with rotating the icon: https://stackoverflow.com/a/8712727/1127492

You may also consider preparing 8 (or 16) (small!) icons for the 8 (or 16) main directions and select the icon depending on bearing/8 (resp. /16).

Community
  • 1
  • 1
Stefan
  • 4,645
  • 1
  • 19
  • 35