How to get only gps location using sencha touch? - android

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.

Related

GPS location detect slow or unable receive [Here SDK]

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);

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 user position by GPS in Sencha

I'm trying to get user position in Sencha Touch 2:
var geo = new Ext.util.Geolocation({
autoUpdate: true,
allowHighAccuracy: true,
listeners: {
locationupdate: function(geo) {
lat = geo.getLatitude();
lon = geo.getLongitude();
// here comes processing the coordinates
}
}
});
But I've got coordinates only from network. There's no GPS icon on Android device, pointing that I'm using GPS. Also it doesn't work when I turn off internet connection. How can I enable GPS positioning? In Manifest file GPS is enabled.
I just got bit by this too.
It turns out there's a bug in Sencha: in Ext.util.Geolocation.parseOption they name the parameter allowHighAccuracy but the w3c specs name it enableHighAccuracy.
I added the following code to my application init to fix that:
var parseOptions = function() {
var timeout = this.getTimeout(),
ret = {
maximumAge: this.getMaximumAge(),
// Originally spells *allowHighAccurancy*
enableHighAccuracy: this.getAllowHighAccuracy()
};
//Google doesn't like Infinity
if (timeout !== Infinity) {
ret.timeout = timeout;
}
return ret;
};
Ext.util.Geolocation.override('parseOptions', parseOptions);
For the record: the bug has been reported over a year ago, and the fix was applied for TOUCH-2804 in a recent build. I don't know what that means, but sure enough the bug is still in 2.0
EDIT: using the approach mentioned above doesn't work well either. The GPS icon would turn on and off as Exts calls getCurrentPosition repeatedly using a setInterval. The reason for doing this is that The native watchPosition method is currently broken in iOS5. In my Android targeted application I ended up ditching Ext:util.Geolocation and directely used navigator.geolocation.watchPosition. After that it worked like a charm.
GPS location provider determines location using satellites. Depending on conditions, this provider may take a while to return a location fix.
Requires the permission android.permission.ACCESS_FINE_LOCATION.
Hey I think you need updated longitude and latitude values .
follow this link.. Click Here
I already tried it and test it in android mobile phone.. Its working.
Note : Must and should test in android mobile phone with on GPS status. It will not show on eclipse emulator. But it will show in mobile phone try it..
have a nice.

Send GPS coordinates to Android emulator using DDMS, telnet or any other means

DDMS is not able to send location to the emulator. I have tried sending just the location from DDMS but still the emulator is not able to receive location. Nothing appears on the DDMS log when I click the Send button.
I tried sending geo fix from telnet which returns OK but doesn't actually update the location, or if it does I can't read it via my application.
The application works properly in the device, is able to capture test location details but not able to capture location data sent to the emulator either via DDMS or telnet.
I am testing on Android 2.2 emulator. Can anyone let me know what is wrong?
My app (below) is written in C# using Mono for Android and may need fixing (I'm a newbie to all things Android so I could have missed something). OnLocationChanged(Location location) just doesn't seem to fire at all, as if the listener isn't properly defined. Any help appreciated.
Note: The first time I run this Activity the LocationManager.GetLastKnownLocation is null but the test provider stuff isn't accessed. When I run it again GetLastKnowLocation is still null but the test provider stuff is accessed and set. Weird.
[Activity(Label = "Location Demo")]
public class LocationActivity : Activity, ILocationListener
{
private TextView _locationText;
private LocationManager _locationManager;
private StringBuilder _builder;
private Geocoder _geocoder;
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.LocationActivity);
_geocoder = new Geocoder(this);
_locationText = FindViewById<TextView>(Resource.Id.TextView1);
_locationManager = (LocationManager)GetSystemService(LocationService);
if (_locationManager.GetLastKnownLocation("gps") == null)
{
_locationManager.AddTestProvider("gps", false, false, false, false, false, false, false, 0, 5);
_locationManager.SetTestProviderEnabled("gps", true);
Location loc = new Location("gps");
loc.Latitude = 50;
loc.Longitude = 50;
_locationManager.SetTestProviderLocation("gps", loc);
}
Location lastKnownLocation = _locationManager.GetLastKnownLocation("gps");
if (lastKnownLocation != null)
{
_locationText.Text += string.Format("Last known location, lat: {0}, long: {1}", lastKnownLocation.Latitude, lastKnownLocation.Longitude);
}
else
{
_locationText.Text += string.Format("Last location unknown");
}
_locationManager.RequestLocationUpdates("gps", 5000, 2, this);
}
public void OnLocationChanged(Location location)
{
_locationText.Text += string.Format("Location updated, lat: {0}, long: {1}", location.Latitude, location.Longitude);
}
public void OnProviderDisabled(string provider){}
public void OnProviderEnabled(string provider){}
public void OnStatusChanged(string provider, Android.Locations.Availability availability, Bundle extras){}
}
Kudos to https://stackoverflow.com/users/170333/greg-shackles for getting me this far.
I think the problem may be with how you're calling RequestLocationUpdates(). That third parameter is the minimum distance the device needs to move before you get updates, so you're telling the system to only send updates after the device has moved 2 meters. If it works on a real device, it's probably because you moved more than 6 feet. :)
Try starting with RequestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this). That will start a stream of updates on a real device, but only one when you press 'Send' in DDMS. Once that works, I would work back from there on how often you get updates.
Also, GetLastKnownLocation() is always null when you start the emulator. It's better for devices since it can send you the network location as a starting estimate, or the GPS location if another program was using it recently.
EDIT
It could also be a permissions issue. Normally you need to alter AndroidManifest.xml to get GPS access. The line is
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
See the docs here.
Call
_locationManager.RequestLocationUpdates("gps", 5000, 2, this);
function before doing any location operations, like below:
base.OnCreate(savedInstanceState);
SetContentView(Resource.Layout.LocationActivity);
_geocoder = new Geocoder(this);
_locationText = FindViewById<TextView>(Resource.Id.TextView1);
_locationManager = (LocationManager)GetSystemService(LocationService);
_locationManager.RequestLocationUpdates("gps", 5000, 2, this); //this will cause updated location to be retrieved from telnet
Note: Its normal that program works after the first run, so that after the first run your application could get the initial updated location from telnet and that will be enough to not throws an exception
Finally resolved this. When the emulator is launched by VS2010 (i.e. F5, start debugging) it does not behave as expected. Launch the emulator externally using AVD.exe, start a virtual device and deploy the app. to it (using F5, start debugging) and everything works fine.
Why starting the emulator from within or outside VS2010 should make any difference is a mystery I am able to live with. Thanks to everyone for their helpful suggestions.
Does your emulated android image have GPS hardware? The description in the emulator should have "hw.gps=yes".
I had the same symptoms before recreating a new image with the right (emulated) hardware. I found a simple web page that displays the current location was handy when debugging the emulation environment.

Android onLocationUpdate not called with GPS_PROVIDER

Hi
I have an Android service using the location manager :
if(locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.i("service","start with GPS"); locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0,locationListener);
}
Then the location listener :
private LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location aLocation) {
Log.i("location listener", "location updated");
}
... other methods ....
}
In the manifest, the authorization for ACCESS_FINE_LOCATION is set.
Everything works ok both in simulator and phone ( Xperia Android 1.6 to 2.2 ) for NETWORK_PROVIDER. It works fine in simulator for GPS_PROVIDER. But when I try to use the GPS in the devices, the location listener is never called. I can see in the DDMS that the GPS is actually working and retrieve locations, but it never calls the listener methods.
There is a strange message though :
WARN/libloc_api(1173): loc_eng_report_position: ignore position report when session status = 1
I can not see what I am missing. Any idea ? Thanks.
It takes a while to get a location fix. The time to first fix de(TTFF) depends on a lot of factors, like number of visible GPS satellites, signal to noise ratio, the GPS chipset etc ...
Here is a nice article that will help you get the best out of GPS on android phones.

Categories

Resources