I tried to add some GeoPoints on my map but I've problems with some “special” points.
The range of the latitude value is +90 to -90 and therefore I want to add a point like the this...
int latitude: 85000000;
int longitude = 45000000;
GeoPoint point = new GeoPoint(latitude, longitude);
...and after this I double check the latitude value with:
point.getLongitudeE6();
I always get a maximum value of 80000000 back. Can someone explain why google set this limit for a GeoPoint and what the reason for this limitation is?
Thanks!
Your issue is with getLatitudeE6(). GeoPoint doesn't work near the poles. You're probably going too far north or too far south.
This behavior is by design. From the docs:
[The latitude] will be clamped to between -80 degrees and +80 degrees
inclusive, in order to maintain accuracy in the Mercator projection.
Likewise, longitude is limited to -180 to +180.
Related
i cant get a response from openweathermap Api if one coordinate is equal than or bigger than 90 and it return message says x is not a float.
screenshot for error response
screenshot for right response
Remember: Latitude from -90 to 90. Longitude from -180 to +180.
Hope it Helps.
Latitude ranges from -90 to 90, and longitude from -180 to 180. Out of those bounds it is not a valid coordinate.
So the fact you received an error makes perfect sense. Though the error could be more descriptive such as 'value for x is not valid'.
You can find more information about latitude longitude coordinates with a simple google search. For example here on http://www.latlong.net/ (emphasis mine):
The latitude has the symbol of phi, and it shows the angle between the straight line in the certain point and the equatorial plane. The latitude is specified by degrees, starting from 0° and ending up with 90° to both sides of the equator, making latitude Northern and Southern. The equator is the line with 0° latitude. The longitude has the symbol of lambda and is another angular coordinate defining the position of a point on a surface of earth. The longitude is defined as an angle pointing west or east from the Greenwich Meridian, which is taken as the Prime Meridian. The longitude can be defined maximum as 180° east from the Prime Meridian and 180° west from the Prime Meridian.
Does anyone know where the separate latitude and longitude distances can be found between two google markers? I can get the total distance using the haversine method such as this:
Find distance between two points on map using Google Map API V2
How can I get each value please?
Thanks
Frank
The Marker class has a Position property, so
double latitudeDifferenceInDegrees = marker1.getPosition().latitude - marker2.getPosition().latitude;
double longitudeDifferenceInDegrees = marker1.getPosition().longitude - marker2.getPosition().longitude;
You can convert the latitude difference into a distance in meters - each degree is equal to 110.574 kilometers:
double latitudeDifferenceInMeters = latitudeDifferenceInDegrees * 110574;
You can't do the same for longitude. On the equator, a longitude degree is about 111 km, but near the poles, it is much less. If you are only using this for short distances, I'd go for
double longitudeDifferenceInMeters = longitudeDifferenceInDegrees * 111320 * Math.cos((marker1.getPosition().latitude + marker2.getPosition().latitude) / 2);
Note that both can give negative values if the first marker lies south or west of the second marker. If you're interested in positive values only, apply Math.abs().
I am developing an application that uses google map to navigate the user to a given location. I want to orient the map so the destination point always be at the top of the map and the current location marker to be at the bottom and both markers to be vertically aligned and centered in the map (e.g the vertical line between them to be perpendicular to the screen)
My approach is to find the mid point of the markers and than to calculate the bearing to rotate the map so both markers end up vertically aligned and centered. Centering the mid point will center the markers but I can't calculate the correct value for the bearing.
Any help will be appreciated.
EDIT:
I've tried Location.bearingTo and Location.distanceBetween. For the same input they return different values and the one returned from Location.distanceBetween is what i am looking for.
EDIT2 (Code example):
public static void positionMap(GoogleMap map, LatLng start, LatLng end) {
// zoom the map so both locations are visible
LatLngBounds bounds = LatLngBounds.builder().include(start).include(end).build();
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds, 200));
// find the bearing
float[] results = new float[3];
Location.distanceBetween(
start.latitude,
start.longitude,
end.latitude,
end.longitude,
results);
float bearing = results[2];
// position the map so the two markers are vertically aligned
CameraPosition position = map.getCameraPosition();
CameraPosition cameraPosition = new CameraPosition.Builder(position)
.target(Utils.median(start, end))
.bearing(bearing)
.build();
map.moveCamera(CameraUpdateFactory.newCameraPosition(cameraPosition));
}
Take a look the the distanceBetween method of a location object.
Here is the doc. The initial bearing is the bearing you need to use from the starting point, the final bearing is the bearing you will be on when you reach the destination. I think you would be interested in the initial bearing.
public static void distanceBetween (double startLatitude, double startLongitude, double endLatitude, double endLongitude, float[] results)
Added in API level 1
Computes the approximate distance in meters between two locations, and optionally the initial and final bearings of the shortest path between them. Distance and bearing are defined using the WGS84 ellipsoid.
The computed distance is stored in results[0]. If results has length 2 or greater, the initial bearing is stored in results[1]. If results has length 3 or greater, the final bearing is stored in results[2].
Parameters
startLatitude the starting latitude
startLongitude the starting longitude
endLatitude the ending latitude
endLongitude the ending longitude
results an array of floats to hold the results
Throws
IllegalArgumentException if results is null or has length < 1
You could try using Location.bearingTo().
Unfortunately this requires converting from LatLng to Location, but that should be simple enough.
first what I want to achive, than I think I can do it
I want to find streets on the edge of area where center point is point where I am standing.
Now for example I'm selecting area with 2km radius. I want to find 360 points (1 point for each degree) and check if point with this coordinates is street or not. Now 3 questions
How to get each point in distance from me
How to get latitude and longitude of this point
How to check if this point is street or not
How to get each point in distance from me
Having the Lat and Lng of source and destination points, you can use Location.distanceBetween method.
float[] results = new float[3];
Location.distanceBetween(srcLat, srcLng, destLat, destLng, results);
The distance between the two points is in index 0 : results[0]
How to get latitude and longitude of this point
Here is a link
How to check if this point is street or not
Here is another link.
Hope this help.
I have a data set of different locations, and want to show the nearest locations (within 5 km).
How can I determine the minimum/maximum of latitude and longitude?
f.e.: I need to fill my car up, and am looking for all gas stations in my neighborhood so I can go to the nearest. How do I do this on an Android phone?
I'd like to avoid iterating through all of the locations as well, because I've got about 2500 locations and rising. Any suggestions on that?
Thank you guys in advance for the advice on this!
Update:
Thank you for the feedback you guys gave me, I solved my issue by iterating through all locations on the server and using the Google Distance Matrix API to calculate the distances: http://code.google.com/intl/nl/apis/maps/documentation/distancematrix/
Simplifying, latitude is the angle over/under the equator, longitude is angle right/left of greenwich meridian.
So to calculate (on average) how much for example 1º latitude is, you convert it to radians (multiply by PI/180), and then multiply by Earth's mean radius (6,371.0 km).
For your question, the process is the inverse one: take 5 km and convert it to degrees:
Divide it by Earth's radius
Multiply by 180/PI
This way you will get delta degrees, that is, how much degrees are 5 kms (on average, if you want exactitude, you will need the exact Earth radius differentials over those 5 kms) with which you can build a circle around the given location (just like a compass would).
All the calcuations give and methods are approximations but well within tolerances for what you require.
The earth circumference is approx 40076000 metres.
the distance traveled per degree of latitude is allways the same and is simply a proportion of the earth circ.
the distance travel per degree in longitude however changes depending upon your latitude ( this rings on the glode get smaller nearer the poles ).
so for a given distance m, the corresponing Latitude and Longitude values are
earthcirc = 40076000;
// at Lat and Lon for distance m (in meters)
LatDelta = (m * 360) / earthcirc;
LonDelta = (m * 360) / abs(eathcirc*cos(lat));
This gives you your square lat long deltas for a simple search of your data. but on fingin a candidate your should then do a full distance calc as the corner of the square is quite a bit more than 5 KM away.
distance between 2 lat/longs
distLat = (lat1-lat2) * earthcirc) / 360;
distLong = (long1-long2) * earthcirc * cos((lat1+lat2)/2) / 360;
dist = sqrt( sqr(distLat) + sqr(distLong) );
I know most compilers/languages use radians for cos/sin functions but its easire to explain in degrees.
as for searching your data the simplest way is to order in be either lat or long then you can do a binary search to find the possible location to check instead of a full scan. There are better ways to order the data ( quad trees ) but for 2500 ish entries i wouldnt bother
There are two issues here, 1) how to calculate the distance between two pairs of lat/lon and 2) how to find the point with shortest distance to a given point.
There are formulas on the net, some more accurate than others, for example http://www.movable-type.co.uk/scripts/latlong.html
This is a (geo) spatial indexing problem (http://en.wikipedia.org/wiki/Spatial_index#Spatial_Index ). You can use for example a quad tree with lat/lng as X/Y (I assume your points are not too close to the polars, which complicate things but still doable). The quad tree let you find in Log(N) time the neighborhood of your car without having to iterate over all points.
Not exact code but hopefully it will help.