2017-11-13 6 views
0

Wie ich MAPBOX in meiner Anwendung verwende.Ich weiß nicht, wie man aktuelle Lat und Long.Ich habe diesen Weg, um den aktuellen Standort zu bekommen.Aber es zeigt Null Objektreferenz .please mir helfen, mein ProblemWie bekomme ich den aktuellen Standort in MAPBOX in android

 mapView = (MapView)view. findViewById(R.id.mapView); 
    mapView.setStyleUrl(Style.MAPBOX_STREETS); 
    mapView.onCreate(savedInstanceState); 

    //Add a mapBoxMap 
    mapView.getMapAsync(new OnMapReadyCallback() { 
     @Override 
     public void onMapReady(MapboxMap mapboxMap) { 
      mapboxMap.setMyLocationEnabled(true); 
      // Set the origin waypoint to the devices location 
      Position origin = Position.fromCoordinates(mapboxMap.getMyLocation().getLongitude(), mapboxMap.getMyLocation().getLatitude()); 

      Log.i("RR","mapboxMap.getMyLocation();"+origin); 
      // Log.i("RR","mapboxMap.getMyLocation();"+mapboxMap.getMyLocation().getLongitude()); 
      mapboxMap.getUiSettings().setZoomControlsEnabled(true); 
      mapboxMap.getUiSettings().setZoomGesturesEnabled(true); 
      mapboxMap.getUiSettings().setScrollGesturesEnabled(true); 
      mapboxMap.getUiSettings().setAllGesturesEnabled(true); 


     } 

    }); 

Antwort

1

mapboxMap.setMyLocationEnabled (true) zu lösen; ist veraltet.

Sie müssen locationEngine verwenden lat zu bekommen und lange wie diese

locationEngine = new LostLocationEngine(MainActivity.this); 
    locationEngine.setPriority(LocationEnginePriority.HIGH_ACCURACY); 
    locationEngine.setInterval(5000); 
    locationEngine.activate(); 
    Location lastLocation = locationEngine.getLastLocation(); 

Verwendung lastLocation.getLatitude(), lastLocation.getLongitude()

Verwandte Themen