How to overcome google static maps API 6 decimal places precision limit? - android

Google Static Maps API Documentation states:
Latitudes and longitudes are defined using numerals within a comma-separated text string that have a precision to 6 decimal places. For example, "40.714728,-73.998672" is a valid geocode value. Precision beyond the 6 decimal places is ignored.
However, I have noted that in many cases, that precision is not enough.
(Edit: Actually, 6 decimal places allows a precision of approximately 2 cms, as 323go comments. See the edit at the bottom for further info)
E.g: Trying to put a marker on the Eiffel Tower (Lat: 48.8583701,Lon: 2.2922926) gets truncated (to Lat: 48.858370, Lon:2.292292) obtaining the following result, which has a non negligible offset:
I use static maps is because in my application I show multiple maps simultaneously inside the items of a RecyclerView.
I currently achieve that by asynchronously injecting the images returned by the Google static maps API via Picasso.
This current approach works well and performs smoothly, the only problem being the lack of precision of the map.
As a workaround, I am considering using the standard MapView in Lite Mode, but I am concerned that it could lead to performance issues, as stated in this question
Is there a way to overcome that limit, even if it requires paying?
Edit
I was using wrong coordinates. I'll explain how I got them, just in case anyone else makes the same mistake.
I was using the coordinates that appear in the URL after loading https://google.com/maps/place/Tour+Eiffel, which in my case is this URL.
When the left side panel of the web version of Google Maps is open (which is the default behaviour), the pin appears to be in the center of the map.
Nevertheless, the coordinates of the URL represent the center of the map including the part under the left panel. This is easy to notice once the left panel is collapsed.
This is what caused the horizontal offset.

Im trying to figure this out but on my side everything is working fine and precise, i noticed you are using different coordinates than mine
For the Eiffel Tower i used:
48.858285, 2.294388
That should give you a better result, also remember you can place a marker with the name of the place or with the full address with Geocoder which is:
Champ de Mars, 5 Avenue Anatole France, 75007 Paris, France
Something like this should help
Geocoder geocoder = new Geocoder(<your context>);
List<Address> addresses;
addresses = geocoder.getFromLocationName(<String address>, 1);
if(addresses.size() > 0) {
double latitude= addresses.get(0).getLatitude();
double longitude= addresses.get(0).getLongitude();
}

Related

How to check if a coordinate are between 2 sets of coordinates (Google Maps - Android)

For example I have:
start (51.533407, -0.203948)
point (51.531966, -0.210987)
end (51.530951, -0.216823)
origin (51.533487, -0.187812)
destination (51.529189, -0.220814)
So, how can I know that "point" is between "start" and "end" and not between "origin" and "start" or "end" and "destination?
I already tried:
minimum distance between coordinates - is not a solution, because can give wrong results;
comparing street name (feature name, thoroughfare, subthoroughfare - Address) with the "html_instruction" from Directions API - is not working everytime and sometimes the street name is null;
comparing street name (feature name, thoroughfare, subthoroughfare - Address) with "long_name" ("address_components") from Geocode API -> useless, because i can't get coordinates from "start" and "end" and sometimes the street name is null (eg: on villages).
Any other ideas? I already searched on the internet but i couldn't find something that I need.
Thank you,
Maxim
Image Link: google map
This is just an analytically solution, its upto you how you can implement with the code (I would recommend using Geofencing API provided in Android's Google Play Services library).
Consider the "point" to be the center of circle.
Find the close point, For Example "Start".
Consider that distance as radius and draw a circle.
You may now know all the coodinates (points) inside the circle.
Find distances from the center to all the points included in the Geofence (Circle).
Subtract each with the "point's" distance.
The minimum distance obtained after subtraction would be the point opposite to the "point".
Hence you can know that in between which two coodinates your "point" lies.
If there are no coordintes in the geofence in the radius drawn between "point" & "start" then increase the radius till the time you dont find the first coordinate. This will be another point besides "point" & "Start".
Hope this would Help!!!

Android Geocoder Returns State Route xx, Can It Return The Actual Street Name?

I'm using Android's Geocoder to get street and suburb for my App, however on some roads, it will return State Route 60 for example, rather than the actual road name.
I'm in Western Australia if that makes any difference.
Is there a way around that ?
Or will I have to guess the street based on latitude and longitude ?
And in the same vein - the Geocoder returns streets as "St" and Roads as "Rd".
I can't find a default way of expanding that. If there is one, I would love to know about it.
I ended up changing the amount of addresses that the getFromLocation method returned to 2, and then adding logic in to detect when the first address is returned contained State Route.
When the first address returned State Route, it would use the second returned address instead.

Wrong reading from Google Place Android API

i have developed an application that interacts with google places api to search for cafe in the neighborhood of a user. for the purpose of my application i want to have the radius set to a very small value.. may be 20 to 50 meters. currently my app is working but its not working the way it should.
In my app, i have set the radius to 350 meters. so practically it should return me the list of cafe that fall in the radius of 350m. however my app still shows starbucks in this result set even if starbucks is 650m (road distance) and 500m (straight distance). I would like to know what should be done to get the correct results.
Currently i am using GPS for this. will a combination of gps and network service provide me a better reading?
public PlacesList search(double latitude, double longitude, double radius, String types)
throws Exception {
this._latitude = latitude;
this._longitude = longitude;
this._radius = radius;
this question is not related to Android, but to the Google Places API.
are you using place search or text search? both of them have comments regarding location biasing
text search:
"You may bias results to a specified circle by passing a location and a radius parameter. This will instruct the Place service to prefer showing results within that circle; results outside of the defined area may still be displayed."
place search:
"distance. This option sorts results in ascending order by their distance from the specified location. Ranking results by distance will set a fixed search radius of 50km. One or more of keyword, name, or types is required."

Android google-maps longitude/latitude calculation question

I have seen it pretty often so far that for some reason the latitude or longitude values return by getLatitude() are multiplicated with 1E6 in Google-Maps-examples. What's the reason for this? Why 1E6? What's wrong with the raw values returned by those functions ?
I think I've read somewhere that this is related to performance. getLatitute() returns a double which is floating-point datatype. Math on floating point datatypes is slow if the device doesn't support floating-point operations.
So by multiplying the double value with 1E6, degrees become microdegree and so the calculation can be done with integer math without loosing too much resolution.
Its not just Google maps, I work with some maritime chart APIs on Windows PCs & they use a mixture on decimal degrees & 1E7 degrees. It just seems to be the functions were written that way & no one is bothered to unify them all.
The reason they are multiplied by 1E6 is because the GeoPoint class (which is used to plot points on a Google Map) uses microdegree latitude and longitude as integers. Multiplying by 1E6 converts degrees into microdegrees. The reason Google chose to do it this way is up to debate, but it probably has to do with the fact that the Google Maps themselves are not extremely accurate, and using a raw double value to 10 or more decimal places returned by the GPS is an unnecessary level of accuracy to plot a point on a Google Map.

convert wgs 84 to lat/long

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.

Categories

Resources