GeoPoint point = new GeoPoint(
(int) (userlocation.getLatitude() * 1E6),
(int) (userlocation.getLongitude() * 1E6));
I am creating geo point like above
but it's not at exact location of user
it's nearly 500 to 600 meters away
Here userlocation is location I am getting from location listener
In user location I get values something like
18.453225455645 & 78.15446456546
But while plotting I can use only
18.453225 & 78.154464
i.e. -- only six digit after decimal. if I try to use extra values marker shows wrong location.(It's due to geopoint needs values in int )
How I can plot exact location on map??
Edited:-- I don't think any one has solution on this. I checked few apps & find out one app called myTaxi which has more accuracy than Google map don't know how they get that. Currently I am just rounding latitude & longitude.
Thank You
a. Just by removing the last few digit after six digits will not give you an error of 500-600 m as 5 digit after decimal places should give you precision of about 1m.
b. Are you using GPS or some other location provider? Use only GPS as Location Provider if you want accurate location. There is a catch though GPS would require a line-of-sight to work correctly.
Related
My app gets updated GPS coordinates periodically which I show using a Marker on map. I need to move the marker to a new position if the new GPS coordinates are different then what Marker is currently showing.
The problem is that comparing Marker.getPosition() is more accurate while LatLang is not, hence sometimes even when they are the same, my logic says they are different.
How to solve this issue?
Please note that the same LatLang i assign to Marker.
You can consider that two LatLngs are virtually the same if the distance between them is less than a given tolerance.
You can use the SphericalUtil.computeDistanceBetween method from the Google Maps Android API Utility Library
float YOUR_TOLERANCE = 1; // 1 meter
if (SphericalUtil.computeDistanceBetween(pos, buslatLng) < YOUR_TOLERANCE) {
// Both locations are considered the same
}
I am trying to develop an android application that can do task according to the lat/long. This is something like if I am in particular suburb (Lets say I am in Belconnen, ACT Australia, I would like to get the details of that place automatically) - if I move out the border of belconnen then I have to show some other details.
If you check this google maps link: http://goo.gl/4mItcF you would see the red border is only belconnen suburb.
My question is how do I give the borders in my App (meaning how do I tell my App that I am now in belconnen, ACT? Is it by getting lat/long along the borders store them in DB and check if I am inside required lat/long, if that is the case DB would have huge numbers only for Belconnen, ACT right?
Or is there an easier way to get the borders?
Let me know!
Thanks!
There is a way , it is called Reverse Geocoding. You can use it by two ways :
1. Using Geocoder class of Android -
Geocoder gcd = new Geocoder(context, Locale.getDefault());
List<Address> addresses = gcd.getFromLocation(lat, lng, 1);
if (addresses.size() > 0)
System.out.println(addresses.get(0).getLocality());
Here you use lat = -35.2374551 and lng = 149.0672515 for Belconnen, ACT Australia. Check out the function getFromLocation for more information.
2. Using Google REST Web Services :
https://maps.googleapis.com/maps/api/geocode/json?latlng=-35.2374551,149.0672515 (JSON)
https://maps.googleapis.com/maps/api/geocode/xml?latlng=-35.2374551,149.0672515 (XML)
pass comma separated latitude and longitude and u will get the most precise location for that in response. Find more information here Reverse Geocoding google API
As soon as you go out of Belconnen, ACT Australia, the address in response will no longer contain this and you can put some logic to get your desired behavior.
As far as i understand, you would like to create a Location Aware Application.
As per the Android documentation, Google Play services location APIs are preferred over the Android framework location APIs (android.location) as a way of adding location awareness to your app.
Step 1 - Knowing the current Location of the User
Google recommends to use FusionProvider API for this purpose. It is one of the location APIs in Google Play services where you can specify requirements at a high level, like high accuracy or low power. It also optimizes the device's use of battery power.
https://developer.android.com/reference/com/google/android/gms/location/FusedLocationProviderApi.html
Step 2 - Based on the latitude and Longitude information retrieved in the location object, you can use the below Google web service to get the postal code of the location.
http://maps.googleapis.com/maps/api/geocode/json?latlng=lattitude,longitude&sensor=true
Step 3 - How Frequent can we retrieve the location information
Turning on the listeners continuously will impact the device battery highly. So, to avoid this, we need to minimize the frequency of retrieving the location information.
I would recommend to measure the distance traveled by the user and based on that set the next location update trigger. Since you are concerned about boundary only, we can set a high value based on the device acceleration.
Refer the below links for more details on how to implement this effectively.
https://stackoverflow.com/a/11644809/623517
Hope this helps.
You can get full address from lat long and then search your city or location. This answer explain how to do it : How to get complete address from latitude and longitude?
If you want further flexibility you can use geofence : http://developer.android.com/training/location/geofencing.html
You can approximate the region with LatLngBounds (com.google.android.gms.maps.model.LatLngBounds).
Use it like this:
LatLngBounds.Builder builder = new Builder();
for (int i=0; i<points.length; i++) {
builder.include(points[i]);
}
LatLngBounds bounds = builder.build();
And then check if your location falls inside it:
if (bounds.contains(myLatLng)) {
//your implementation
}
I know this approach cannot give perfect results but it seems to be more efficient then using the geofences.
LocationManager lm;
lm=(LocationManager)this.getSystemService(Context.LOCATION_SERVICE);
Criteria c=new Criteria();
String provider=lm.getBestProvider(c, false);
Location l=lm.getLastKnownLocation(provider);
double latitude = l.getLatitude(); // latitude
double longitude = l.getLongitude(); // longitude
I am trying to get the GPS location co-ordinates(lat and lon vals) for every 100metrs.
For example, I am at particular location A and tried to fetch my current location using
location listener and shown in the map with marker, after that I have travelled 100metres and reached location B and again i tried to fetch location and shown in map with marker.
Good thing :-
i am getting but obvious new lat and lon cordinates for every next 100 meters.
Annoying Thing:-
Marker for location A and for location B getting overlapped always, so one cannot make out any sort of difference in between those two locations by dirrectly looking into map :(. How can I overcome this issue. Can you please guide me.?
I am new to Android. In my application, customer is at a location. I want to find agents near-by to that customer using his/her latitude and longitude. How can I do this? customer is on one location & We want to search agents surronding that perticular customer.
I have latitude of customer and agents and based on I want to search agents(From customer's latitude longitude in surrounding area of 5 km. which agents are thare that i want to search).
pseudocode
area = 100;
for a over allAgents
if(Math.abs(a.x - customer.x) < area || Math.abs(a.y - customer.y) < area)
nearCustomerArray.add(a);
If you already know agent's location, grab you current location using built-in device gps receiver.
Then, calculate distance between your coordinates and the one of the agent using distanceTo method of Location class
Finally, found the small distance among all the distances you calculated.
Hi
I am having a little trouble figuring out how to convert between types of coordinates. I have a list of coordinate sets with the following description
"Coordinates are always in the WGS84 system. All coordinates a represented as integer
values x and y where the coordinate value is multiplied with 1,000,000."
An example:
559262 6319512
Well, I need to convert these to long/lat (and back) so i can use these in google maps (android). But this is not as easy as it seams. I have been searching around and did find some code to do this, but it does not seam to work properly. Anyone who can provide some code for doing this? If possible, I would like to avoid a big geo framework (it has to be used in an android application).
thanks.
best regards, kenneth
EDIT:
I did find a solution on my own. I downloaded the class described here:
http://www.ibm.com/developerworks/java/library/j-coordconvert/
And it works fine. Hope someone can find it useful.
I am sorry for posting before having done my homework decently. Thanks to everyone who posted
If you're getting the location from the GPS on android, you will get a Location object that holds Lat/Long as doubles. In order to display a point on Google Maps, you need to turn these double values into a GeoPoint object using:
GeoPoint location = new GeoPoint(
(int) (mLocation.getLatitude()) * 1E6),
(int) (mLocation.getLongitude()) * 1E6)
);
Hope thats helpful.
All GPS systems give their latitude and longitude with respect to the WGS84 model of the Earth. Unless you intend to give the lat/lon with respect to a nation's local model, such as the British OSGB36 model, you should be fine treating the coordinates you have as representing microdegrees. Even here in the Britain, the Admiralty now print their nautical charts with lat/lon relative to WGS84, I expect the Ordnance Survey land maps will follow suit soon, if they haven't already done so.