Calculate the center point of multiple latitude/longitude coordinate pairs

Thanks! Here is a C# version of OP’s solutions using degrees. It utilises the System.Device.Location.GeoCoordinate class public static GeoCoordinate GetCentralGeoCoordinate( IList<GeoCoordinate> geoCoordinates) { if (geoCoordinates.Count == 1) { return geoCoordinates.Single(); } double x = 0; double y = 0; double z = 0; foreach (var geoCoordinate in geoCoordinates) { var latitude = geoCoordinate.Latitude * Math.PI … Read more

Calculate distance in meters when you know longitude and latitude in java [duplicate]

Based on another question on stackoverflow, I got this code.. This calculates the result in meters, not in miles 🙂 public static float distFrom(float lat1, float lng1, float lat2, float lng2) { double earthRadius = 6371000; //meters double dLat = Math.toRadians(lat2-lat1); double dLng = Math.toRadians(lng2-lng1); double a = Math.sin(dLat/2) * Math.sin(dLat/2) + Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)) … Read more

R – Finding closest neighboring point and number of neighbors within a given radius, coordinates lat-long

Best option is to use libraries sp and rgeos, which enable you to construct spatial classes and perform geoprocessing. library(sp) library(rgeos) Read the data and transform them to spatial objects: mydata <- read.delim(‘d:/temp/testfile.txt’, header=T) sp.mydata <- mydata coordinates(sp.mydata) <- ~long+lat class(sp.mydata) [1] “SpatialPointsDataFrame” attr(,”package”) [1] “sp” Now calculate pairwise distances between points d <- gDistance(sp.mydata, … Read more

Using Address Instead Of Longitude And Latitude With Google Maps API

See this example, initializes the map to “San Diego, CA”. Uses the Google Maps Javascript API v3 Geocoder to translate the address into coordinates that can be displayed on the map. <html> <head> <meta name=”viewport” content=”initial-scale=1.0, user-scalable=no”/> <meta http-equiv=”content-type” content=”text/html; charset=UTF-8″/> <title>Google Maps JavaScript API v3 Example: Geocoding Simple</title> <script type=”text/javascript” src=”http://maps.google.com/maps/api/js?sensor=false”></script> <script type=”text/javascript”> var … Read more