2016-06-01 11 views
0

Ich verwende OSMDROID. Derzeit, wenn ich mich bewege, bleibt die Karte so wie sie ist (die Nordrichtung bleibt oben auf meinem Bildschirm), aber ich möchte die Karte entsprechend der Richtung des Geräts drehen. z.B. Wenn ich mich in Richtung Osten bewege, dreht sich die Karte von der rechten Seite und zeigt nach Osten auf den Bildschirm meines Geräts.OSMDROID: Wie man OSM-Karte als Richtung des Gerätes dreht?

Gibt es dafür eine Lösung?

Antwort

2

Es gibt ein Beispiel in der Beispielanwendung. Hast du es schon angeschaut? Es ist nicht perfekt, und Sie werden es ergänzen wollen mit gps

https://github.com/osmdroid/osmdroid/blob/master/OpenStreetMapViewer/src/main/java/org/osmdroid/samplefragments/SampleHeadingCompassUp.java

`` ``

//lock the device in current screen orientation 
    int orientation = getActivity().getRequestedOrientation(); 
    int rotation = ((WindowManager) getActivity().getSystemService(
      Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation(); 
    switch (rotation) { 
     case Surface.ROTATION_0: 
      orientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT; 
      this.deviceOrientation=0; 
      break; 
     case Surface.ROTATION_90: 
      this.deviceOrientation=90; 
      orientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE; 
      break; 
     case Surface.ROTATION_180: 
      this.deviceOrientation=180; 
      orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT; 
      break; 
     default: 
      this.deviceOrientation=270; 
      orientation = ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE; 
      break; 
    } 

    getActivity().setRequestedOrientation(orientation); 


    LocationManager lm = (LocationManager) getActivity().getSystemService(Context.LOCATION_SERVICE); 
    try { 
     //on API15 AVDs,network provider fails. no idea why 
     lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, (LocationListener) this); 
     lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, (LocationListener) this); 
    } catch (Exception ex) { 
    } 
    compass = new InternalCompassOrientationProvider(getActivity()); 
    compass.startOrientationProvider(this); 
    mMapView.getController().zoomTo(18); 

`` ``

eingerichtet, um die Drehung Überschrift, unter Berücksichtigung Gerätedrehung

``

@Override 
public void onOrientationChanged(float orientation, IOrientationProvider source) { 
    //System.out.println("compass " + orientation); 
    //System.out.println("deviceOrientation " + deviceOrientation); 
    //this part adjusts the desired map rotation based on device orientation and compass heading 
    float t=(360-orientation-this.deviceOrientation); 
    if (t < 0) 
     t+=360; 
    if (t > 360) 
     t-=360; 
    //System.out.println("screen heading to " + t); 
    mMapView.setMapOrientation(t); 
} 

`` ``

+0

das ist nicht das, was ich wollte ... –

+1

ok, gut es tut, was Sie beschrieben. Aktualisieren Sie die Beschreibung oder geben Sie weitere Informationen für Ihre Zwecke an. Vielleicht ist das, was Sie wollen ... https://github.com/osmdroid/osmdroid/blob/44408833ca2c16c5cf35b8681e9fa02ef3099263/osmdroid-android/src/main/java/org/osmdroid/views/overlay/gestures/RotationGestureOverlay.java – spy

+0

manchmal Alles über ein Keyword. Ich habe die Antwort bekommen. durch die einstellung der karte habe ich es geschafft. Vielen Dank für Ihre Hilfe. –