I’ve implemented Google map & fuse location API to get current location.
But facing issue like unable to get current location (blue dot) after accepting permission at run time .
This is happened only in fresh installed app, if i kill the app and reopen the app then its works fine.
am i missing something?
Thanks
Enable your location
map.setMyLocationEnabled(true);
Add
map.setMyLocationEnabled(true); in
onRequestPermissionsResult() method So it will update the current location after you accept the permission
Related
I would have thought that requesting the "lastKnownLocation" would return a saved coordinate (GeoPoint) that points to the last known location of the device (from when it last had access to the GPS functionalities).
According to some tests (made on OSMDroid's GpsMyLocationProvider), it seems like requesting that location returns a NullPointer.
GpsMyLocationProvider provider = new GpsMyLocationProvider(MainActivity.mainActivity);
provider.addLocationSource(LocationManager.NETWORK_PROVIDER);
locationOverlay = new MyLocationNewOverlay(provider, map);
I've been trying to set up default GeoPoint for centering the map when it is first launched, and then recentering the map where the GPS now has confirmed a position.
The problem is that provider.getLastKnownLocation() returns a NullPointer exception unless it is given time to actually get the current location from the GPS.
What am I getting wrong here? Shouldn't the "last known location" be a GeoPoint that is saved in memory on the phone and always have something there, unless the phone never ever had access to GPS localization ?
Please see https://developer.android.com/training/location/retrieve-current
You must set the permissions correctly too. Note that at the bottom they describe why the location may be null so see these for troubleshooting.
If you're using an emulator see How to emulate GPS location in the Android Emulator?
I am working on app. When user click on button he will get current location using GPS.
All is working fine but one problem.
Problem
There might be some location where gps will not work...like closed area...and gps can not find location...at that time it will return previously know location...Previously known location may be too older or wrong.
so at that time I want no location found instead of last location.
Is there any way to check if fix is available or not ?
i need help as soon as possible, right now, i have developed a app that must show current Location Client, and i have try http://developer.android.com/training/location/retrieve-current.html and its work well, but i want to show the client location without clicking the button, i have try to change the memthod getLocation(), but everytime i have tried to call method getLocation(), my app always error,
nb: i have removed the parameter of getLocation() and the xml i already change too. i have try to put the method in onCreated and also in onStart, it's error
anybody can help me please to solve my problem?
for Google map v2(the latest version),you should implements the LocationSource to update current location , than also you do need make a location request use LocationClient to get current location then update it with LocationSource.OnLocationChangedListener
I'm working on an indoor GPS application and I have my own location provider that will give me lat and long. I have google maps v2 working with my location provider by using
mMap.setMyLocationEnabled(true);
mMap.setLocationSource(myLocationProvider);
My problem is as I set the location source to my custom provider, the little blue icon that displays onscreen location no longer functions. Is this expected? Shouldn't google maps just use the lat/long to display the current location, no matter where it comes from?
The blue dot should still be visible.
If you are sure your LocationSource is implemented properly, and after you call OnLocationChangedListener callback method the blue dot does not appear in the location you send, I suggest creating a simple working example to show the issue and post it on gmaps-api-issues.
I would start with a test call in activate:
Location location = new Location("myProvider");
location.setLatitude(30.0);
location.setLongitude(30.0);
listener.onLocationChanged(location);
so I have been developing this app for a few weeks now using my own handheld device and today I was trying to get Google map to center in on the current user location in my app
map.setMyLocationEnabled(true); //Locate the current position of the user
The setLocationEnabled(true) above should normally show the location of the user on the map and when the GPS button is pressed it will zoom into it. However after I added the following code this does not work anymore it doesn't show the location of the user anymore and I also I notice "Google Settings" was installed onto my device which after looking around was an update by Google so it might not be the code itself. But I do not know if Google Settings is the cause for this.
LocationManager service = (LocationManager) getSystemService(LOCATION_SERVICE);
Criteria criteria = new Criteria();
String provider = service.getBestProvider(criteria, false);
Location location = service.getLastKnownLocation(provider);
LatLng userLocation = new LatLng(location.getLatitude(),location.getLongitude());
map.moveCamera(CameraUpdateFactory.newLatLngZoom(userLocation, 15));
Even after commenting out this block of code the problem still persist. I do not know how to fix this and I hope someone could help me. I am not sure if this has to do with the code itself or just my device, it literally does not get the location of the user at all even though it was working for the past few weeks and it doesn't give any errors or warnings even pressing the GPS button on my map gives nothing no errors or warnings.
EDIT: I tried using an older working version of my code for this app and it still does not work in terms of getting the user location to come up on the map.
Thanks.
Why you dont use:
map.animateCamera(CameraUpdateFactory.newLatLngZoom(new LatLng(map.getMyLocation().getLatitude(),map.getMyLocation().getLongitude()), 15));
The map store your actual location, so you dont need LocationManager class.