GPS location detect slow or unable receive [Here SDK] - android

when trying start navigation in some indoor environment, it will unable receive the GPS signal or detect with very slow, but when using other navigation app(Waze/Google Map/Here) the problem does not occur.
And also some indoor place can receive the gps signal without any problem.
below is my code for PositionListener
naviManager.addPositionListener(new WeakReference<NavigationManager.PositionListener>(positionListener));
private NavigationManager.PositionListener positionListener = new NavigationManager.PositionListener() {
#Override
public void onPositionUpdated(GeoPosition loc) {
// the position we get in this callback can be used
// to reposition the map and change orientation.
loc.getCoordinate();
loc.getHeading();
loc.getSpeed();
// also remaining time and distance can be
// fetched from navigation manager
naviManager.getTimeToArrival(true, Route.TrafficPenaltyMode.DISABLED);
naviManager.getDestinationDistance();
}
};

How are you starting the positionManager, maybe you have only passed the GPS option and not the GPS_NETWORK option ?
positioningManager.start(PositioningManager.LocationMethod.GPS_NETWORK);

Related

Get current location as fast as possible with Google Play Services?

I am developing an android application in which I need to get my current Location. I have successfully wrote the code and I am getting my current location using Google Play Service.
The problem is sometimes it gives me the location after a long time. I have noticed that it was only for first use of the app.
Any way to avoid this problem and get the current location fast? Is it related to the version of google play service in my code? (I am not using the last one in fact I am using version 9.8.0.)
As #tahsinRupam said, avoid using getLastLocation as it has a high tendency to return null. It also does not request a new location, so even if you get a location, it could be very old, and not reflect the current location. You might want to check the sample code in this thread: get the current location fast and once in android.
public void foo(Context context) {
// when you need location
// if inside activity context = this;
SingleShotLocationProvider.requestSingleUpdate(context,
new SingleShotLocationProvider.LocationCallback() {
#Override public void onNewLocationAvailable(GPSCoordinates location) {
Log.d("Location", "my location is " + location.toString());
}
});
}
You might want to verify the lat/long are actual values and not 0 or something. If I remember correctly this shouldn't throw an NPE but you might want to verify that.
Here's another SO post which might help:
What is the simplest and most robust way to get the user's current location on Android?

Android LocationManager requestLocationUpdates changed?

My app is working in Ice Cream Sandwich perfectly well, but now I tried it on KitKat and faced some problems.
The app is kind of server I'm running in my old phone and it provides location when requested. In ICS when the location is requested the GPS icon starts blinking and soon the app receives location update and sends it forward. But now with KitKat the GPS icon does not start blinking when location is requested. The app gives 60s time for finding the GPS location, but usually the GPS isn't even activated during this time. Still now and then the GPS suddenly activates itself (during the 60s) and the location is provided to my app.
Why the GPS doesn't get activated even my app requests location? As said, my app works with ICS without problems. And I do have required permissions set in my manifest.
public variables:
public static LocationManager mlocManager = null;
public static LocationListener mlocListener_fast = null;
onCreate:
mlocListener_fast = new MyLocationListener();
mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
Handling user requested command (location request)
mlocManager.requestLocationUpdates( LocationManager.GPS_PROVIDER, 0, 0, mlocListener_fast);
What should I do differently to get the GPS location instantly without waiting for sudden location updates/GPS activation, probably triggered by Android or some other app?? Unfortunately I don't have any other Android device I could try this.
EDIT:
It seems that if the app does not request location at startup, then the location request works every time when requested time after time. But if the location was requested (and received) on startup, then the location request does not work anymore. What can cause that? I use exactly the same line (the same location mgr and the same location listener) for location request on startup and later if requested.
Even if the location listener used in startup is different than the one used later, the location request does not work anymore. Tried even initialize the location mngr again just before requesting the location again and it did not help. What's with this??
EDIT2:
It just seems that with KitKat it's not possible to request multiple location requests. I used to have several location listeners for different purposes. For example one for updating location once per hour and another for getting location instantly (user requested update). Now it seems that if I have the 1/60min location listener running as normal, then KitKat location manager fails to handle the instant location requests. Have anyone faced this issue? Would be good to know which Android versions have this issue.
Workaround for this issue is to use only one LocationManager and one LocationListener. If your app has needs for different kind of simultaneous location requests (with different parameters), then you need to implement a "location request handler" which decides which parameters should be used for the location request i.e. which parameters have the tightest requirements for location.
Here is a simple example code that explains the idea of "location request handler":
class LR {
long lock_min_time; // defined in set_lock_lr before using
float lock_min_dist;
boolean lock_active = false;
long idle_min_time = 3600000; // 1 per hour
float idle_min_dist = 200;
boolean idle_active = true;
long fast_min_time = 0;
float fast_min_dist = 0;
boolean fast_active = false;
//constructor
public LR()
{}
public void set_lock_lr(long min_time, float min_dist, boolean active)
{
lock_active = active;
lock_min_dist = min_dist;
lock_min_time = min_time;
System.out.println("LR lock set: "+min_time+", "+min_dist+", "+active);
update_location_request();
}
public void set_idle_lr(boolean active)
{
idle_active = active;
System.out.println("LR idle set: "+active);
update_location_request();
}
public void set_fast_lr(boolean active)
{
fast_active = active;
System.out.println("LR fast set: "+active);
update_location_request();
}
private void update_location_request()
{
// Remove current location request
mlocManager_basic.removeUpdates(mlocListener_basic);
if(fast_active)
{
mlocManager_basic.requestLocationUpdates(LocationManager.GPS_PROVIDER, fast_min_time, fast_min_dist, mlocListener_basic);
System.out.println("LR: fast_active");
}
else if(lock_active)
{
mlocManager_basic.requestLocationUpdates(LocationManager.GPS_PROVIDER, lock_min_time, lock_min_dist, mlocListener_basic);
System.out.println("LR: lock_active");
}
else if(idle_active) // only idle updates
{
mlocManager_basic.requestLocationUpdates(LocationManager.GPS_PROVIDER, idle_min_time, idle_min_dist, mlocListener_basic);
System.out.println("LR: idle_active");
}
}
}

Get information of Location Services enabled/disabled using Fused Location Provider

I am working on an app which uses Google Maps and tracks user's location. I want to change the visibility of the "You are here!" marker when the user closes Location Services by hand or services goes to condition of inaccessible. This method can return the information of whether Location Services enabled or not:
private boolean isLocationServicesEnabled() {
LocationManager lm = (LocationManager) getSystemService(LOCATION_SERVICE);
if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER) || lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
return true;
}
return false;
}
However, I do not want to detect the status of Location Services for once. Whenever the user opens or closes Location Services, I should detect it and change the visibility of marker. In short, this sloppy pseudocode explains what I want to listen:
while application runs
if location services turn off
change marker visibility to false
else
change marker visibility to true
I did not find a way to achieve this task without android.location.LocationListener, want to achieve it just using Fused Location Provider. Do you have any idea? Here is the core structure I used if you want to see:
http://www.androidhive.info/2015/02/android-location-api-using-google-play-services/
(Check the title of "Complete Code")
Doing this the proper way involves a huge amount of code. You have to make use of the location SettingsApi class.
The main entry point for interacting with the location
settings-enabler APIs.
This API makes it easy for an app to ensure that the device's system
settings are properly configured for the app's location needs.
Fortunately there is a full blown sample provided by Google on github
How about implementing a gps listener?
mLocationManager.addGpsStatusListener(new GpsStatus.Listener(){
#Override
public void onGpsStatusChanged(int event) {
if(event==GpsStatus.GPS_EVENT_STARTED){
Log.d(TAG,"Gps Started");
}else if(event==GpsStatus.GPS_EVENT_STOPPED){
Log.d(TAG,"Gps Stopped");
}
}
});
modify the above code to change visibility of your marker. Hope this works.

How to get only gps location using sencha touch?

I have created sencha touch application and i want to try get the current location of android device using below code.
Ext.create('Ext.util.Geolocation',
autoUpdate: true,
allowHighAccuracy: true,
listeners: {
locationupdate: function(geo) {
latitude=geo.position.coords.latitude;
longitude=geo.position.coords.longitude;
if(Global.currentUserPositionMarker)
{
latlng1=new google.maps.LatLng(latitude, longitude);
currentPosMarker.setPosition(latlng1);
}
}
}
});
In my device the gps icon will be blinking but Couldn't get the current location of device gps position.
It always get current location from my network provider.
I want frequently update current location from the device gps possition.
Like the google map app for android the gps icon is always stable, i want to like that in my application.
start your Device WI-FI and then try to load your app.
Because It will work for me to get the current location from gps.
I have face the same problem to get the current location from gps.
I am also add question for releated these problem See The Question.
Add Frequency parameter in GeoLocation object.
Ext.create('Ext.util.Geolocation',
autoUpdate: true,
frequency:1000,
allowHighAccuracy: true,
listeners: {
locationupdate: function(geo) {
latitude=geo.position.coords.latitude;
longitude=geo.position.coords.longitude;
if(Global.currentUserPositionMarker)
{
latlng1=new google.maps.LatLng(latitude, longitude);
currentPosMarker.setPosition(latlng1);
}
}
}
});
Frequency value is in milliseconds and it is used to update Geo location by given time.

LocationListener works on emulator, not on phone

I'm having trouble getting a LocationListener to call the onLocationChanged() callback on my phone. When I run my code in the emulator, it works fine, the callback is called each time I do a geo fix.
When I run the application on my phone, nothing at all happens. The callback is never called. I have location enabled by both GPS and by Wireless in my settings. The application has all of the uses-permissions for location permissions.
Also, when I call getLastKnownLocation() on a LocationManager object, my application crashes. (Still, only on my stupid phone). Even if I try to catch an exception that's causing it to crash, it still just crashes, so I can't even get any information on what is causing it to crash. This is extremely frustrating.
LocationManager.getBestProvider() is returning GPS, and when I open google maps it finds my location in no time at all. What the heck is going on here? Is there some way I can figure out why it's crashing on my phone?
private void setupLocListener(){
Criteria c = new Criteria();
c.setAccuracy(Criteria.ACCURACY_FINE);
c.setAltitudeRequired(false);
c.setBearingRequired(false);
c.setSpeedRequired(false);
c.setCostAllowed(false);
lm.requestLocationUpdates(lm.getBestProvider(c,true), 0, 0, new LocationListener() {
#Override
public void onLocationChanged(Location arg0) {
map.setLocation(arg0);
}
public void onProviderDisabled(String arg0) {
}
public void onProviderEnabled(String arg0) {
}
public void onStatusChanged(String arg0, int arg1, Bundle arg2) { }
});
}
onLocationChanged() wont fire until you actually start receiving GPS coordinates.
By that I mean the chip has to warm up for about a minute or so from my experience before you start receiving data from it.
I usually start some other application and wait for it to prove that the GPS chip has warmed up before I go testing any of my GPS apps.
I know that you mentioned that it works properly in Google Maps but have you tried clearing your memory and restarting your application straight away afterwards?
Also getLastKnownLocation() is always null until you start receiving coords.
The Location framework pushes coordinates to your callback, when they become available. Depending on weather, etc. you may not get a "fix" initially. You should see the "GPS" indicator on the status bar when your listener is successfully registered.
getLastKnownPosition() works just fine (it may return null); and Google Maps uses that, while it is waiting for an initial fix from the location provider.
You may also want to see what other providers are available, e.g. cell-tower data, and attempt to obtain data from those (i.e. LKP), either instead of, or until, your "preferred" provider starts pushing data.
Also, don't assume any particular service exists, e.g. LocationManager (Context.getSystemService() can return null), or any suitable provider exists, (getBestProvider() can return null). Your code will fail as-is on the right device with the right settings. If the documentation says null you must check for it, or users will be uninstalling it because it FC's all over the place.

Categories

Resources