I have an third party application which saves lat and lng values as below in the db.
lat lng lat_dir lng_dir
2824.2311 07703.0962 N E
The problem is, It is not clear on which unit lat lng values are saved in DB.
I have tried to convert in degree by assuming the values in KM. After Lat comes some where nearby If I assume,But in no way lng comes. lng values is more away that I can assume.
Any Guidence is appreciated.
PS. I have no control over third party application, and there is no document present over lat lng calculation by third party application.
Google map requires the lat and lng to be in the decimal format. The format that the third party application is storing is used by some GPS tracking devices. I don't recall what the format is called though.
You will need to convert the lat / lng to decimal format before plotting it on the map. Given below is the Java code to convert it into a decimal format.
private static String getCordinate(String location) {
int len = location.length();
String decimals = location.substring(len-7);
Float decimalf = Float.parseFloat(decimals) / 60;
String first = location.substring(0,len-7);
Float coordinate = Float.parseFloat(first) + decimalf;
return coordinate.toString();
}
Coordinate Format - Latitude : 1907.51672 & Longitude : 7252.34810
Output Format : Latitude : 28.403852 & Longitude : 77.051605
The location is as follows on Google Maps
Related
I have this coordinate: 778597.3125000001, 9148353. I am told this coordinate is Arc 1960 / UTM zone 36S.
When I go here and click "Get Position on Map" and enter in the above coordinates, it places the point in the correct place on the map (at the corner of a field).
What kind of transform/projection do I have to do to make it Latitude and Longitude, and then go to the same point in Google Maps?
I have tried various ways but seems to end up 400 - 200m diagonal offset.
The correct latitude and longitude should be: Lat: -7.699944 Long: 35.5262575 (corner of the field, see link):
I am using DotSpatial.
var Arc1960UTMZone36S = KnownCoordinateSystems.Projected.UtmOther.Arc1960UTMZone36S;
Arc1960UTMZone36S.AuthorityCode = 21036;
var WGS1984 = KnownCoordinateSystems.Geographic.World.WGS1984;
//4326 google earth
//3857 for google maps
WGS1984.AuthorityCode = 3857;
double[] xy = new double[2] { 778597.3125000001, 9148353 };
double[] z = new double[1] { 0d };
Reproject.ReprojectPoints(xy, z, Arc1960UTMZone36S, WGS1984, 0, 1);
var latitude = xy[1];
var longitude = xy[0];
Debug.WriteLine($"Lat: {latitude} Long: {longitude}");
Would anybody know why it is offset?
The solution was to use proj4 string instead of the Known Coordinate System.
Instead of
var Arc1960UTMZone36S = KnownCoordinateSystems.Projected.UtmOther.Arc1960UTMZone36S;
Arc1960UTMZone36S.AuthorityCode = 21036;
Use
String proj4_21036_str = "+proj=utm +zone=36 +south +ellps=clrk80 +towgs84=-160,-6,-302,0,0,0,0 +units=m +no_defs";
ProjectionInfo proj21036 = ProjectionInfo.FromProj4String(proj4_21036_str);
although, I don't understand why.
I'm looking for the easiest way convert utm to lat / long
If the server-side code is better.
for example utm
EASTING NORTHING
521937.7447 3955151.601
Thank you
In order to convert UTM coordinates (easting and northing) to latitude and longitude you need the zone number and zone letter as well.
Without these your easting / northing values could be in any of the 60 zones defined by UTM.
As for libraries, there are packages for Python, Javascript and probably others.
Sample for JS:
utm.toLatLon(easting, northing, zoneNum, zoneLetter)
//returns { latitude, longitude }
utm.fromLatLon(latitude, longitude)
//returns { easting, northing, zoneNum, zoneLetter }
You can use ST_Transform in Postgis if you have access to this
https://postgis.net/docs/ST_Transform.html
Example:
ST_AsText(ST_Transform(ST_SetSRID(the_geom, 27700), 4326)))
How would be the algorithm to convert the following GPS coordinates (Java language prefered)?
From UTM/SAD69:
Latitude: 7171359,145
Longitude: 716431,81
Zone: 22
Hemisphere: South
To Decimal (Google Maps friendly):
Longitude: -48.8461461196
Latitude: -25.559740724
http://maps.google.com.br/maps?q=-25.559740724,-48.8461461196&hl=pt-BR&t=h&z=16
You could utilize UTMConverter.java for that purpose, the following example:
double easting = 716431.81;
double northing = 7171359.145;
int zone = 22;
boolean isSouthHemishere = true;
LatLng value = UTMConverter.convertToLatLng(easting,northing,zone,isSouthHemishere);
System.out.println(value);
gives the same result (lat: -25.55933783,lng:-48.84565751) as Geographic/UTM Coordinate Converter online tool
Use PROJ.4 to convert from EPSG:29192 (SAD69 / UTM zone 22S) to EPSG:4326 (WGS 84).
For example here is a simple interface to transform, but there are others for command line, JavaScript, etc.
I'm experimenting with System.Data.Spatial.DbGeography, that I want to use to determine the distance from one coordinate to another (going to be stored in SQL server).
My coordinates are in lat/long, and I got them from Bing Maps (I've tried with coordinates from Google Maps too, with the same result).
var osloCentralStation = DbGeography.FromText("POINT(59.9109 10.7523)", 4326);
var drammen = DbGeography.FromText("POINT(59.7378 10.2050)", 4326);
Console.WriteLine("Distance: {0}km", osloCentralStation.Distance(drammen) / 1000);
Returns:
Distance: 63,4340839088124km
The returned distance is approximately double what it should be.
https://maps.google.com/maps?saddr=59.9109+10.7523&daddr=59.7378+10.2050
Does anybody have any idea as to what's going on?
You're not declaring the element in WKT in the right order.
WKT should be in your case:
POINT(10.2050 59.7378)
See OGC standard here:
http://msdn.microsoft.com/en-us/library/bb933834.aspx
http://en.wikipedia.org/wiki/Well-known_text
And then it has to be declared like:
POINT(LONGITUDE LATITUDE)
Also keep in mind that it won't be the driving distance but the distance by air.
It turns out that lat/long are given as long/lat when creating new DbGeography objects.
I've written a little helper method so that I don't get it wrong again in the future:
private static DbGeography CreateDbGeography(double latitude, double longitude, int srid = 0)
{
var text = string.Format(CultureInfo.InvariantCulture.NumberFormat, "POINT({0} {1})", longitude, latitude);
if (srid > 0)
{
return DbGeography.FromText(text, srid);
}
return DbGeography.FromText(text);
}
This question already has an answer here:
Closed 10 years ago.
Possible Duplicate:
Calculate “as the crow flies” distance php
I am trying to develop a GoogleMaps page where I can get the user location and show custom marker points from an XML file that fells within the calculated area around the user.
To make things more clear :
I have a radius parameter from WebConfig file, say 5000 (in meters)
I've found the user location on map,
Using the xml list that I own (xml has the Lat-Long values of
each store) I want to put custom markers on map which fell within
the 5 km^2 area range with the user's location as center.
Is there a way to achieve this goal?
How do I calculate a point's Lat & Long values by only passing user's location coordinates and a distance parameter (say 5000 in my case)?
Edit :
My XML doc is kinda huge including whitegoods stores all around the
country. My main problem is to filter these rows of data (long,latt)
using user's current location.
I need something like:
func distanceCale(int long, int latt, int radius)
to return me some values that can help me filter my XML data.
I guess my question was not clear enough at the firs place. :)
You can achieve this using the Haversine formula. This formula has been used in a Demo from an XML file showing markers within a given radius.
For your application the javascript code is used to generate markers from XML file.
function deg2rad(degrees){
radians = degrees * (Math.PI/180);
//document.write(radians);
return radians;
}
function Haversine(lat1,lon1,lat2,lon2) {
deltaLat = lat2 - lat1 ;
deltaLon = lon2 - lon1 ;
earthRadius = 3959; // in miles 6371 in meters.
alpha = deltaLat/2;
beta = deltaLon/2;
a = Math.sin(deg2rad(alpha)) * Math.sin(deg2rad(alpha)) + Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * Math.sin(deg2rad(beta)) * Math.sin(deg2rad(beta)) ;
c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
distance = earthRadius * c;
return distance.toFixed(2);
}
The Haversine function is used when parsing XML
var radius = document.getElementById('radiusSelect').value;
for (var i = 0; i < markerNodes.length; i++) {
var lat = parseFloat(markerNodes[i].getAttribute("lat"));
var lng = parseFloat(markerNodes[i].getAttribute("lng"));
var latlng = new google.maps.LatLng(
lat,
lng);
var distance = Haversine(center.lat(),center.lng(),lat,lng);
if(distance<=radius) {
createOption(name, distance, i);
createMarker(latlng, name, distance);
bounds.extend(latlng);
}