Reputation:
I am using JellyBean 4.2 and testing on my device.
How to get current location on clicking myLocationButton.
getMYLocation is returning null on using Network Provider.
I am using LocationManager to get current location and referring to Google documentation https://developers.google.com/maps/documentation/android/start.
After this clicking on MyLocatiionButton is not bringing any change
Upvotes: 0
Views: 3501
Reputation:
basically what you should do is make a call to Google Directions API receive the road direction coordinates (many Latlng points), and then draw a polyline between each one of them.
U can user either overview_polyline or legs and steps.
Upvotes: 1
Reputation: 39052
You need to add a LocationSource to your map fragment. Please see this answer for a discrete example.
Upvotes: 1
Reputation: 1125
Use this code Id it does work.
private LocationManager locationManager;
private Location location;
private boolean hasGpsProvider, hasNetwrokProvider;
public Location getLocation(Context mContext) {
if (locationManager == null) {
locationManager = (LocationManager) mContext
.getSystemService(Context.LOCATION_SERVICE);
}
hasGpsProvider = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
hasNetwrokProvider = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (hasGpsProvider) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER, 0, 100, locationListenerGps);
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
return location;
}
if (hasNetwrokProvider) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER, 0, 100,
locationListenerNetwork);
location = locationManager
.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
return location;
}
return location;
}
And call
if (location != null) {
lat = location.getLatitude();
lng = location.getLongitude();
}
Upvotes: 0
Reputation: 22038
Do you have all permission set in the Manifest? Also, you have to enable the location service (is the gps icon in the status bar showing?). It'll take some time for the device to get the location, so see if onLocationChanged is called.
Upvotes: 0