Find all lat/long under certain radius - math

I have set of lat/long which are stored in database and I have to find all the lat/long from the database which are lies between the given lat/long(e.glatitude = 37.4224764,and longitude=-122.0842499) and given radius(say 5miles).For this I need to do some addition and subtraction like:
37.4224764 + 5mile
37.4224764 - 5mile
and
-122.0842499+5mile
-122.0842499-5mile
But I don't know how the conversion works here.

You're a little vague in your requirements, do you just want to find out the coordinates of a point a certain distance from your current location in a given direction? Or get a circle of a radius of a particular distance around your coordinates? Or draw a line of a certain length from your coordinates to another point a particular distance away?
I assume you'd probabaly want to use the Geometry spherical library, e.g.
var latLng = new google.maps.LatLng(geometry.location.lat, geometry.location.lng);
var newLatLng = google.maps.geometry.spherical.computeOffset(
latLng,
1000,
0
);
see also https://developers.google.com/maps/documentation/javascript/geometry#Distance
PS: you need to add the geometry library parameter when loading the map:
<script src="https://maps.googleapis.com/maps/api/js?v=3&libraries=geometry"></script>

Related

Set current location in a route based on a arbitrary distance

I'm just playing around with Here and this is my escenario for an idea.
Get a routing between 2 points, I know this is doable
Set the start and finish marker, I know this is doable
Get the distance between the 2 points, I know this is doable
Now, if the distance from point 1 and 2 is 3000 meters I want to set a marker ( You are here ) based on a arbitrary distance value, let say I want to add a marker at the 1750 meters point, the market should appears in the half route way.
Is this posible with the actual API?
Thanks in advance!
Yes it is possible to do with HERE javascript API.
Once you get routing response and create H.geo.LineString out of it, you can calculate distance between each two geo points from that line string using H.geo.Point#distance method. This will help to determine between which two points (lat, lng) is your desired arbitrary distance.
After that you need to calculate angle between these two geo points and use it in method H.geo.Point#walk in order to get exact position of the geo point you need.
Here you can find jsfiddle example which places marker on the simple LineString based on desired arbitrary distance.

is there a way to set heading for a Point?

I have heading that i get with this computeHeading(from:LatLng, to:LatLng), latlng of one point and distance to second point(in meters) is there a way using these three things to get latlng of second point ?
From google docs Navigation Functions
Given a particular heading, an origin location, and the distance to travel (in meters), you can calculate the destination coordinates using computeOffset().

Calculating end points of a rectangle with two given lat long points and breadth

I need to check whether a point lies within a given rectangle on a map. I am using leaflet to create bounding boxes which requires me to provide the south-west and north-east points of the rectangle.
I have the following information:
1. middle point of the top edge of the rectangle
2. middle point of the bottom edge of the rectangle
3. length of edge (i.e. breadth) = 1000 m.
It is safe to assume that the two points above are very close.
Any ideas on how this can be achieved will be helpful.
First, to get the upper left and lower right points, you'll need to use some geometry. This page: https://gis.stackexchange.com/questions/2951/algorithm-for-offsetting-a-latitude-longitude-by-some-amount-of-meters is a great example of how to accurately convert from meters to decimal degrees.
For example, in order to get the upper-left point, you are starting with the middle point of the line, and you have the total length of the line, you'll want to divide the length of the line by 2, then convert that length from meters to decimel degrees, then add the X coordinate by that amount. That will give you the upper-right corner. Repeat this for the lower-left corner by subtracting that amount instead of substracting.
var upperMiddlePoint = [30,50];
var segmentLength = 5000;
var northEastPoint = upperMiddlePoint;
var northEastPoint.x = northEastPoint.x + ((segmentLength / 2) * DECIMAL_DEGREES_PER_METER)
There's a quick and easy answer here: Simple calculations for working with lat/lon + km distance? that describes how to get the DECIMAL_DEGREES_PER_METER value in the above snippet.
To create a LatLngBounds object to represent your rectangle bounds. API Here.
var bounds = new L.LatLngBounds(southWestPoint, northEastPoint);
Then, use the LatLngBounds.contains() function, as described here, to determine if your point falls within these bounds.
var contains = bounds.contains([50, 30]);
if (contains) {
doStuff();
}
The contains boolean will be true if the bounds contain the point, false if not.

All latitude and longitude within 1 mile circle area

I am trying to generate pins over the map of my database coordinates by using fusion table and I want to generate only within 1 mile area circle around the specific location. To get 1 mile area's coordinates similar to my db coordinates I've to put condition of < and > to fusion table but I don't know how to get all the coordinates within 1 mile area circle or what should be the value for condition in query. Can any one please help me to figure out, it'll really appreciable.
You haven't provided any code, so I'm not exactly sure what you want to do. But the Fusion Table ST_INTERSECTS operator should do what you want. Look for <spatial_condition>.
var where = "ST_INTERSECTS('location_col',CIRCLE(LATLNG(31.954109,-115.441528), radius_in_meters) ) )";
var qryOpts = {
query: {
select: location_col,
from: table_id,
where: where
}
};
ft_layer.setOptions(qryOpts);
I have no idea if that is possible within the Fusion Tables API but, if I were doing it, I would first calculate which points in my database were within the radius and insert only those. You can ignore the earth's curvature and just use the Pythagorean theorem with a little adjusting for your latitude.
See here: http://www.movable-type.co.uk/scripts/latlong.html

Google Maps API v3 Polylines not drawing

App works this way:
User enters a starting location and a distance. User can choose to draw circles, or lines over the roads. Circles work fine. Lines used to work.
When Lines, the code finds the lat/long of the starting location, then for the points N, S, E, W of the origin at the distance set by the user (say, 100km). Starting with the N destination, the code calls google.maps.DirectionsService() to get directions from the origin to N. This returns an array of lat/longs in the the route.overview_path.
NOTE: I COULD use the directionsRenderer() to draw the route, BUT, the distance drawn would be greater than the distance set by the user. Drawing the entire route from the origin to the point N might be 124km over the roads, and I just want to draw 100km.
Instead, I step through the route.overview_path[] array, checking the distance between that point and the point of origin, adding each point to a new array. When the distance is greater than the dist set by the user, I stop, pop off the last element, then create a new Polyline based on this 2nd, smaller array.
I've spent the entire day in Chrome's developer mode walking through the javascript, setting breakpoints, watching locals, etc. The array of points passed in google.maps.Polyline({}) is a good array of unique points. I just cannot figure out why they aren't rendering.
Ultimately, the code used to draw 4 lines starting at the point of origin, one heading North, one heading East, South, West. etc....
The code is here: http://whosquick.com/RunViz.html
Thank you for your attention.
Nevermind. Solved it.
var objGeo = new LatLon(Geo.parseDMS(myroute.overview_path[0].Pa), Geo.parseDMS(myroute.overview_path[0].Qa));
I had inadvertently switched Pa with Qa.

Resources