I have a long list of locations in excel format and I need to calculate driving distance between these locations using lat&long. Is there any macro I can use.
Cheers
from : link
this is too simple
Miles:
=ACOS(COS(RADIANS(90-Lat1)) * COS(RADIANS(90-Lat2)) + SIN(RADIANS(90-Lat1)) *
SIN(RADIANS(90-Lat2)) * COS(RADIANS(Long1-Long2))) * 3959
Kilometers:
=ACOS(COS(RADIANS(90-Lat1)) * COS(RADIANS(90-Lat2)) + SIN(RADIANS(90-Lat1)) *
SIN(RADIANS(90-Lat2)) * COS(RADIANS(Long1-Long2))) * 6371
Related
I have two locations and I have the formula to get the distance between them but I want to calculate the travel time between them without using google maps or any API calling. Is there any formula to do that in flutter?
I think the real travel time depends on a lot of factors, for example the road you take or the speed limit.
Whitout some complex elaboration, which are usually perfomed by a backend, I don't think it is possible to calculate it.
Anyway, since you have got the distance, you could simply estimate it by giving a supposed speed and then using basic physics formulas.
time = distance / speed.
You cannot find the travel distance between two locations without using the Google API.
However you can get the air distance in meters using this formula in flutter.
double calculateDistance(
double lat1, double lon1, double lat2, double lon2) {
var p = 0.017453292519943295;
var c = cos;
var a = 0.5 -
c((lat2 - lat1) * p) / 2 +
c(lat1 * p) * c(lat2 * p) * (1 - c((lon2 - lon1) * p)) / 2;
var temp = 12742 * asin(sqrt(a));
return (temp * 1000);
}
How to calculate distance between two location in dart?
Without using plugin
double calculateDistance(lat1, lon1, lat2, lon2){
var p = 0.017453292519943295;
var c = cos;
var a = 0.5 - c((lat2 - lat1) * p)/2 +
c(lat1 * p) * c(lat2 * p) *
(1 - c((lon2 - lon1) * p))/2;
return 12742 * asin(sqrt(a));
}
result is KM. if you want meter just multiply by 1000. return 1000 * 12742 * asin(sqrt(a))
You can use geolocator plugin to calculate to distances between two coordinates:
An Example:
var _distanceInMeters = await Geolocator().distanceBetween(
_latitudeForCalculation,
_longitudeForCalculation,
_currentPosition.latitude,
_currentPosition.longitude,
);
Check out GeoLocator Plugin for more info.
Check out latlong. It's a package dedicated to work with coordinates and features sophisticated calculations.
Unlike packages like geolocator it does not come with integrated location services and can be used alongside packages specialized for that.
You can use latlong2 which is the continuation of latlong. It has features like distance calculation and path drawing. So you can get distance as path distance as well as direct distance.
I am using postgres and postgis.
I have Posts which have a geometry, with an attribute visible_within_m which is how many meters from that point the Post should be shown in results.
I can find Posts within some random radius of some random points by doing ST_DWithin(geometry, ST_SetSRID(ST_Point(a, b), 4326), 10000)
However, I want to know how many Posts are visible with a radius of some random point.
How can I look up how many Posts are visible within a radius of some arbitrary point?
Is there a better way to do this?
You can calculate the distance between each point and the center of your circle. If the distance is grater than the radius then it is outside otherwise it's inside.
const EARTH_RADIUS = 6371000;
const toRad = function(num){return num*Math.PI/180};
var calculateDistance =
function(lat1, lon1, lat2, lon2){
var dLat = toRad(lat2 - lat1);
var dLon = toRad(lon2 - lon1);
var a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(toRad(lat1)) *
Math.cos(toRad(lat2)) * Math.sin(dLon / 2) * Math.sin(dLon / 2);
var distance = EARTH_RADIUS * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
return distance;
}
Instead of using a constant value for the distance, use the value stored in visible_within_m
SELECT * FROM mytable
WHERE ST_DWithin(geometry, ST_SetSRID(ST_Point(a, b), 4326), visible_within_m);
On a side note, st_dwithin with geometries uses the distance unit of the projection, so for 4326 it is a (meaningless) distance in degrees, not in meters.
I am new to Power BI and DAX, so I hope you can help me.
I have two tables without any relationship:
Table A contains lat/lng and date of tracked positions.
Table B contains lat/lng and names of all stadiums.
I want to find the closest stadium near the tracked position. Also if possible I want to validate, if the position was in a specific radius of that stadium.
Any help greatly appreciated.
Here's one possible approach:
First, calculate the minimal distance using the Haversine function.
Add this as a calculated column to your Tracked table.
Nearest =
MINX(Stadiums,
ROUND(2 * 3959 *
ASIN(SQRT(
SIN((Stadiums[Lat] - Tracked[Lat]) * PI()/360)^2 +
COS(Tracked[Lat] * PI()/180) * COS(Stadiums[Lat] * PI()/180) *
SIN((Stadiums[Lon] - Tracked[Lon]) * PI()/360)^2)), 1))
In this formula, 3959 is the radius of the Earth in miles.
We can now match up distances to find the nearest stadium:
Stadium = CALCULATE(MAX(Stadiums[Stadium]),
FILTER(Stadiums,
ROUND(2 * 3959 *
ASIN(SQRT(
SIN((Stadiums[Lat] - Tracked[Lat]) * PI()/360)^2 +
COS(Tracked[Lat] * PI()/180) * COS(Stadiums[Lat] * PI()/180) *
SIN((Stadiums[Lon] - Tracked[Lon]) * PI()/360)^2)), 1)
= Tracked[Nearest]))
Note: I rounded the values to avoid not matching from possible floating point errors. This may or may not be necessary.
As my question states that's I am looking for a function/formula that can calculate a distance between two points. Now I have looked at example and found great functions but none of them seem to work they all return 0 when I supply 2 sets of points. Basically I will need to pass the function the following (lat1,lon1,lat2,lon2) and get back the distance. From this distance I can check a check if another point is close by.
UPDATE
Okay so I am now using the following function,
BEGIN
DECLARE pi, q1, q2, q3 , roundedVal FLOAT ;
DECLARE rads FLOAT DEFAULT 0;
SET pi = PI();
SET lat1 = lat1 * pi / 180;
SET lon1 = lon1 * pi / 180;
SET lat2 = lat2 * pi / 180;
SET lon2 = lon2 * pi / 180;
SET q1 = COS(lon1-lon2);
SET q2 = COS(lat1-lat2);
SET q3 = COS(lat1+lat2);
SET rads = ACOS( 0.5*((1.0+q1)*q2 - (1.0-q1)*q3) );
RETURN FORMAT((6371 * rads) , 1);
END
This works fine with Kilometres, but what I am looking for is meters. So I know I have the change the numbers in that function but which ones and what to. Any help ?
I have used this webiste in the past and it has worked for me. Has lots of useful formulas and gives examples in javascript.
http://www.movable-type.co.uk/scripts/latlong.html
I'd recommend you take a look at a spacial extention to MySQL.
http://dev.mysql.com/doc/refman/5.0/en/spatial-extensions.html
If you don't fancy that, this blog might have some use to you:
http://zcentric.com/2010/03/11/calculate-distance-in-mysql-with-latitude-and-longitude/
Try this query
$qry = "SELECT *,(((acos(sin((".$latitude."*pi()/180)) *
sin((`Latitude`*pi()/180))+cos((".$latitude."*pi()/180)) * cos((`Latitude`*pi()/180))*
cos(((".$longitude."- `Longitude`)*pi()/180))))*180/pi())*60*1.1515) as distance FROM
'MyTable` WHERE distance >= ".$distance."
apply this on the values
double theta = src_longitude - dest_longitude;
double min_distance = (Math.sin(Math.toRadians(src_latitude)) * Math.sin(Math.toRadians(dest_latitude))) +(Math.cos(Math.toRadians(src_latitude)) * Math.cos(Math.toRadians(dest_latitude)) * Math.cos(Math.toRadians(theta)));
min_distance = Math.acos(min_distance);
min_distance = Math.toDegrees(min_distance);
min_distance = min_distance * 60 * 1.1515 * 1.609344;