1

I have an application in which I have to plot the position of user and his friend's position on same map but problem is the positions are not accurate.For example the two coordinates like: 81.445679 25.678998 and 81.448902 25.670123. In my application I'm getting my location and then plotting the same on map but I think the type casting from double to int is making these differences.The code for that part is shown below:

 locationManager = (LocationManager)this.getSystemService(LOCATION_SERVICE); 
 Location location=locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER); 
 location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);

 int latitude = (int)(location.getLatitude() * 1000000);
 int longitude = (int)(location.getLongitude() * 1000000);

 point = new GeoPoint(latitude,longitude);
 mapController.animateTo(point);

And to send these coordinates to user's friend I'm sending these coordinates as a string text,something like this:

 private double longitude,latitude;
 latitude=location.getLatitude();
 longitude=location.getLongitude();
 String message = latitude + " " + longitude ; 

and then sending this message to user's friend and at friend side,extracting this location by breaking this message into doubles.So might be parsing from double to string and then string to double is one reason of lack of accuracy.

I'm not clear.So can anyone give me some idea about this ? Or can tell me about what kind of modifications that can be done to the existing codes ?

Thanks in advance.

dark_shadow
  • 3,503
  • 11
  • 56
  • 81
  • Please provide example output and illustrate the problem: e.g., what do you expect to see vs. what you're actually seeing. – Bob Cross Nov 18 '11 at 13:49
  • 1
    What accuracy are you looking for? By nature, phones GPS devices are not very accurate. – GETah Nov 18 '11 at 13:54
  • In my application the point shown on map goes away from actual building on zooming the map.so how can I correct that? – dark_shadow Nov 18 '11 at 14:57

2 Answers2

1

In your code, your setting your location from the locationManager using the GPS provider, then you are over-writing it with a location from the locationManager using the NETWORK provider. The NETWORK provider will typically provide the least accurate location. If you use the GPS provider, you can get location accuracy from typically 50m to 2m radius.

It's got little to do with casting errors.

You can check, programmatically, to see if GPS is on or not - if not, you can pop an alert to the user to switch it on.

Community
  • 1
  • 1
John J Smith
  • 11,435
  • 9
  • 53
  • 72
  • But if I'm using GPS then it is not working on actual device.Even I know GPS is more accurate than Network_provider but on actual devices it is not working.I have tested it on Samsung Galaxy. – dark_shadow Nov 18 '11 at 14:49
  • You need to ensure that GPS is turned on on the device. – John J Smith Nov 18 '11 at 15:13
  • I checked that several times but failed.Is there any fault or some kind of bug ? When I'm using network_provider then it's working fine but only problem is accuracy,then.Please help me. – dark_shadow Nov 18 '11 at 15:29
  • I don't think there is any need for programmatically checking if GPS is on or not.It is on as I said earlier.I have checked it with another application which come inbuilt in Android that is GPS to see different paths.On that map it is showing my position but not showing that same location in my application if I use GPS_provider.Instead shows 0.0 0.0 as surrent location of user.Any ideas what is possibly going wrong? – dark_shadow Nov 18 '11 at 16:37
  • If you are indoors or amongst tall buildings, your GPS update can take a long-time so the onLocationChanged method does not get called. – John J Smith Nov 18 '11 at 20:09
1

You probably won't get an accurate position from a cellular phone.

Usually the receivers in cellular phones are rather cheap and optimized for engery saving and not for accuracy.

For accurate positions the user needs to have a straigth view to the sky. He should not stand next to high houses etc..

You can try to get averages from his current position though.

Udo Held
  • 12,314
  • 11
  • 67
  • 93
  • well this is not possible in my case since I have to make use of internet connectivity to load maps in applications which is possible only if I'm in some certain building. – dark_shadow Nov 18 '11 at 16:39
  • If you are not on the upper-most floor GPS usually won't work. The cellular can however guess where it is based on the mobile network and wlan hotspots. – Udo Held Nov 18 '11 at 16:47