Determine the position between the two positions on the map in android studio - google-maps

We have two position A and B with the specified characteristics on the map.
We want to position out between these two points at a distance of 50 meters.
enter image description here

You can use the geometry library for this:
https://developers.google.com/maps/documentation/javascript/geometry
https://developers.google.com/maps/documentation/javascript/reference/3/#spherical
From the docs:
Navigation Functions
When navigating on a sphere, a heading is the angle of a direction from a fixed reference point, usually true north. Within the Google Maps API, a heading is defined in degrees from true north, where headings are measured clockwise from true north (0 degrees). You may compute this heading between two locations with the computeHeading() method, passing it two from and to LatLng objects.
Given a particular heading, an origin location, and the distance to travel (in meters), you can calculate the destination coordinates using computeOffset().
In your case you might want to get the heading first
var heading = google.maps.geometry.spherical.computeHeading(latLngFrom, latLngTo)
then you can get the offset location:
google.maps.geometry.spherical.computeOffset(latlngFrom, distance, heading)

Related

what's the appropriate algorithm for locating places using Cartesian coordinate system

what's the algorithm to be able locate and display places around me within a particular distance such as 100m,using easting and northing and name of the place where I'm based .
To be more clear, lets suppose I'm based in charing cross and I want to find all places within 100m using easting and northing data for example, easting =10000m and easting=20000m.
Thank you
Pythagoras is the relevant maths.
If your position is (x,y) then you can calc a distance to any other point (x2,y2) with:
distance = sqrt((x2-x)^2 + (y2-y)^2)
So you could just loop over all points, calc their distance and order the results by nearest first.
For large data sets this may become impractical, in which case you'll want to partition the points into large rectangles. The first stage then is to identify which rectangle your (x,y) is within and the adjacent rectangles, then loop through all points in those rectangles. You need the adjacent rectangles because your (x,y) might be right on the boundary of its rectangle.
More generally this partitioning approach comes under the general heading of spatial hashing. For very large areas you want a tree structure known as a quadtree, that breaks large areas down into smaller and smaller regions, but that might be overkill for what you want.
I am assuming by Cartesian coordinates you also mean linear. If you are trying to do this using actual earth coordinates this answer gets more complicated (as we aren't on a flat earth). For simple linear coordinates you could do something like:
bool contains( x, y)
{
return (x >= minx) && (x <= maxx) && (y >= miny) && (y <= maxy);
}
The min, max coordinates would be your current position + how far out you wanted to go. I think this is what you wanted to know. If you need accurate earth coordinates you might look into some geospatial libraries. If you need and estimate you can still use the algorithm above but I would use something like Rhumb lines to calculate the min, max coordinates.

Converting Pixels to LatLng Coordinates

Hello Programming World,
I am using the Google Maps API v3 and I have a map overlay that I need specific coordinates from.
In the image, I've managed to convert the two pixel coordinate sets from the top left and bottom right into latitude and longitude coordinates manually. I've found these equalities:
Top Left:
(1px [x-axis], 1px [y-axis]) in pixels equals...
(-109.05005006119609° [Longitude], 41.00062580014626° [Latitude]) in latitude/longitude
Bottom Right:
(575px [x-axis], 423px [y-axis]) in pixels equals...
(-102.0423399657011° [Longitude], 36.99314427042206° [Latitude]) in latitude/longitude
However, my boss later decided that he'd rather have Google Maps draw this with Google's polyline drawing class (so I need every border angle that I drew in my overlay in latitude/longitude coordinates).
My question is, given these two sets of coordinates, is there some sort of equation or formula that I can use so that I can find the pixel coordinate (which I already have in an image map file) and convert it to a latitude/longitude coordinate.
Example: Point of interest at 132px x-axis and 10px y-axis = a° Longitude and b° Latitude
Find a and b.
I appreciate the help,
Llewgnolm
I talked to a friend of mine and he answered my question, so I figured I'd post the results here for anyone who'd like to know.
What we did was create a system of linear equations:
Lat/Lng = Multiplier*Pixels+Constant (L=m*p+c)
We substituted the numbers that I found manually into two equations for the system, i.e. (for Longitude):
-109.05...=m*(1)+c and
-102.04...=m*575+c and solved both for m and c
Eventually, the numbers came out to be (for longitude):
m = 0.01220895749767
c = -109.06228374530811
We can then use our values for m and c to plug in any pixel value to this equation and find the Latitude/Longitude, i.e (from the example numbers listed above again, for Longitude):
L = 0.01220895749767(132) - 109.06228374530811
L (Longitude at 132px in the x-direction) = -107.45070135561566°
This finds the degree values based off of the images pixels down to the 14th decimal (more than enough). For latitude, I just made a different system of equations with the latitude-based numbers inside to find different m and c values. Hope this helps anyone who stumbles across a similar problem.

How do I find the angle between the center of the earth and two latitude-longitude coordinates

I've got two LatLon (latitude-longitude) objects which represent two locations on the surface of the globe. I want to find the angle (in radians) between the center of the earth and these two LatLon objects.
I'm going to use this angle and the radius of the earth to calculate the arc length between the two locations (I figure this will give better precision than using simple Pythagoras, and be faster than computing the great circle distance).
I already have code to give me the Pythagorean distance and the great circle distance.
Using something like this - how to calculate the angle between two vectors
I thought this at first (after some calc on paper) is this Pythagorean thing?
angle_between_radian = sqrt(deltaLA^2 + deltaLO^2)*PI /180
edit: delta = delta>180?360-delta:delta
We working on sphere then above must wrong ^^. But this link may help:Calculate distance, bearing and more between Latitude/Longitude points.

Get imagery for a rectangle in Google Static Maps API

I have two LatLong points: the upper left and bottom right points of a rectangle and I would like, using the Google Maps API, to retrieve satellite imagery for this rectangle.
I understand that since the zoom level is an integer I might not be able to get this exact rectangle but there's no problem if I get a bigger pixmap as long as I am able to calculate the bounding box for the pixmap in latlong coordinates.
Since the pixmap size is fixed (let's say 640x640) and I have it's center, how to find the appropriate zoom level and calculate the bounding box for the pixmap?
Found a python reference linked in the old Google Maps API blog that provides the function CalculateBoundsZoomLevel.
The source file is here.
def CalculateBoundsZoomLevel(self, bounds, view_size):
"""Given lat/lng bounds, returns map zoom level.
This method is used to take in a bounding box (southwest and northeast
bounds of the map view we want) and a map size and it will return us a zoom
level for our map. We use this because if we take the bottom left and
upper right on the map we want to show, and calculate what pixels they
would be on the map for a given zoom level, then we can see how many pixels
it will take to display the map at this zoom level. If our map size is
within this many pixels, then we have the right zoom level.
Args:
bounds: A list of length 2, each holding a list of length 2. It holds
the southwest and northeast lat/lng bounds of a map. It should look
like this: [[southwestLat, southwestLat], [northeastLat, northeastLng]]
view_size: A list containing the width/height in pixels of the map.
Returns:
An int zoom level.
"""
zmax = 18
zmin = 0
bottom_left = bounds[0]
top_right = bounds[1]
backwards_range = range(zmin, zmax)
backwards_range.reverse()
for z in backwards_range:
bottom_left_pixel = self.FromLatLngToPixel(bottom_left, z)
top_right_pixel = self.FromLatLngToPixel(top_right, z)
if bottom_left_pixel.x > top_right_pixel.x :
bottom_left_pixel.x -= self.CalcWrapWidth(z)
if abs(top_right_pixel.x - bottom_left_pixel.x) <= view_size[0] \
and abs(top_right_pixel.y - bottom_left_pixel.y) <= view_size[1] :
return z
return 0

How do I draw the points in an ESRI Polyline, given the bounding box as lat/long and the "points" as radians?

I'm using OpenMap and I'm reading a ShapeFile using com.bbn.openmap.layer.shape.ShapeFile. The bounding box is read in as lat/long points, for example 39.583642,-104.895486. The bounding box is a lower-left point and an upper-right point which represents where the points are contained. The "points," which are named "radians" in OpenMap, are in a different format, which looks like this: [0.69086486, -1.8307719, 0.6908546, -1.8307716, 0.6908518, -1.8307717, 0.69085056, -1.8307722, 0.69084936, -1.8307728, 0.6908477, -1.8307738, 0.69084626, -1.8307749, 0.69084185, -1.8307792].
How do I convert the points like "0.69086486, -1.8307719" into x,y coordinates that are usable in normal graphics?
I believe all that's needed here is some kind of conversion, because bringing the points into Excel and graphing them creates a line whose curve matches the curve of the road at the given location (lat/long). However, the axises need to be adjusted manually and I have no reference as how to adjust the axises, since the given bounding box appears to be in a different format than the given points.
The ESRI Shapefile technical description doesn't seem to mention this (http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf).
0.69086486, -1.8307719 is a latitude and a longitude in radians.
First, convert to degrees (multiply by (180/pi)), then you will have common units between your bounding box and your coordinates.
Then you can plot all of it in a local frame with the following :
x = (longitude-longitude0)*(6378137*pi/180)*cos(latitude0*pi/180)
y = (latitude-latitude0)*(6378137*pi/180)
(latitude0, longitude0) are the coordinates of a reference point (e.g. the lower-left corner of the bounding box)
units are degrees for angles and meters for distances
Edit -- explanation :
This is an orthographic projection of the Earth considered as a sphere whose radius is 6378137.0 m (semi-major axis of the WGS84 ellipsoid), centered on the point (lat0, lon0)
In OpenMap, there are a number of ways to convert from radians to decimal degrees:
Length.DECIMAL_DEGREE.fromRadians(radVal);
Math.toDegrees(radVal) // Standard java library
For an array, you can use ProjMath.arrayDegToRad(double[] radvals);
Be careful with that last one, it does the conversion in place. So if you grab a lat/lon array from an OMPoly, make a copy of it first before converting it. Otherwise, you'll mess up the internal coordinates of the OMPoly, which it expects to be in radians.