Follow user location in Android SDK

14 posts / 0 new
Last post
lloureirofertagus
Follow user location in Android SDK

Hi,

I used example code to follow user location 

private void enableUserTracking(MapView mapView) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
}

 

But i get a error about visibility off method : setMyLocationTrackingMode not public, not found.

In android sdk, how i follow user location?

Thanks


MQBrianCoakley
Is com.mapbox.mapboxsdk
Is com.mapbox.mapboxsdk.constants.MyLocationTracking imported before using it?

rtarantino
setMyLocationTrackingMode and view.MapView

Hi,

I'm also getting errors on the Use the User's Location Example.  I copied the example verbatim:

package com.vmcomlab.myfirstmapquestapp; //my app name
import android.Manifest;
import android.app.Activity;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;

import com.mapbox.mapboxsdk.constants.MyLocationTracking;
import com.mapquest.mapping.maps.MapView;
//import com.mapquest.mapping.view.MapView;

public class MainActivity extends Activity {

private MapView mMapView;

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

setContentView(R.layout.activity_main);

mMapView = (MapView) findViewById(R.id.mapquestMapView);

enableUserTracking(mMapView);

mMapView.onCreate(savedInstanceState);
}

private void enableUserTracking(MapView mapView) {
if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
return;
}
mapView.setMyLocationTrackingMode(MyLocationTracking.TRACKING_FOLLOW);
}
}

thanks,

Roy

 

'setMyLocationTrackingMode(int)' is not public in 'com.mapbox.mapboxsdk.maps.MapView'. Cannot be accessed from outside package

also complaining that view in in the following statement cannot be resolved:

import com.mapquest.mapping.view.MapView;

I changed it to:

import com.mapquest.mapping.maps.MapView;

not sure if that's correct.

 

 

 

 


MQBrianCoakley
Yup, that code is a little
Yup, that code is a little old and needs to be replaced. We should have that new code put together and updated soon. Sorry for the inconvenience.

PriteshD
Code update

Y haven't you updated the code yet? It's been almost 4 months now. So what's the alternative can u plzz tell me asap? 


maroof
Code Update?

Hi MQBrianCoakley ,

I am still facing the same issue. Can you let me know where can I find the updated code?


Josselin
This should achieve what you want…

mMapboxMap.setMyLocationEnabled(true); seems to do the stuff


PriteshD
sorry not working

the alternative you suggested isn't working....


MQBrianCoakley
Here is the code I'm using
Here is the code I'm using that's working great.   public class MainActivity extends AppCompatActivity { private MapboxMap mMapboxMap; private MapView mMapView; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); MapboxAccountManager.start(getApplicationContext()); setContentView(R.layout.activity_main); mMapView = (MapView) findViewById(R.id.mapquestMapView); mMapView.onCreate(savedInstanceState); mMapView.getMapAsync(new OnMapReadyCallback() { @Override public void onMapReady(MapboxMap mapboxMap) { mMapboxMap = mapboxMap; mMapboxMap.setMyLocationEnabled(true); } }); } }

maroof
Half solution

The code you posted only allow to enable current location with blue dot. BUT what about the current lat/lng. As I need current lat/lng (like OnLocationChanged).


MQBrianCoakley
The best way to grab the
The best way to grab the location is to setup a listener for a location service. The sdk does not provide a good way to get the current location unless you're using the sdk’s built in MyLocationView class. Even then, there is no way to listen to changes. You can just call getMyLocation on MapboxMap when you need the location.

maroof
Not working

Has anyone solved the issue? I am still facing the same issue.


Asendo
Im having the same issue her

Im having the same issue her tying to get current latlng with map sdk. Has anyone fixed it yet?


MQBrianCoakley
Have you tried calling
Have you tried calling getMyLocation on MapboxMap when you need the location?