How do I convert these coordinates to coordinates readable by Google Maps?
Asked Answered
A

4

9

Take a look at the map coordinates on this page. This is linked in from Wikipedia and the coordinates are passed the query string. I'm not sure of the actual terms for this but How do I convert the coordinates? They look like this:

37° 14′ 6″ N, 115° 48′ 40″ W

I would like them to look like this:

37.235, -115.811111

, which is a format readable by Google maps, as seen in this example.

How do I do this in PHP, and what are the two different types of coordinates called?

Aksoyn answered 15/6, 2009 at 12:2 Comment(0)
P
28

The original format is in hours, minutes, seconds format. To convert to decimal, do:

D = H + M/60 + s/3600

So in your example, 37,14,6 becomes

37 + 14/60 + 6/3600 = 37.235, as stated.

If the latitude is N the result is positive, if S, negative. If the longitude is E the result is positive. If west the result is negative.

Pearlypearman answered 15/6, 2009 at 12:7 Comment(0)
N
1

Here is the Javascript function that does what you are talking about.

This utility permits the user to convert latitude and longitude between decimal degrees and degrees, minutes, and seconds. For convenience, a link is included to the National Geodetic Survey's NADCON program, which allows conversions between the NAD83 / WGS84 coordinate system and the older NAD27 coordinate system. NAD27 coordinates are presently used for broadcast authorizations and applications.

This utility requires that Javascript be enabled to perform the calculations.

Nanete answered 15/1, 2014 at 14:9 Comment(0)
D
0

My PHP Code from this Post, Thank You!

function GetLatLon_FromExif($GPS){
$Lat_Ref = $GPS['GPSLatitudeRef'];
if($Lat_Ref == "S") { $Lat_Neg = "-"; }
$Lat_H = explode("/" ,$GPS['GPSLatitude']['0'])[0];
$Lat_M = explode("/" ,$GPS['GPSLatitude']['1'])[0];
$Lat_S = explode("/" ,$GPS['GPSLatitude']['2'])[0];
$Lat_S2 = explode("/" ,$GPS['GPSLatitude']['2'])[1];

$Lon_Ref = $GPS['GPSLongitudeRef'];
if($Lon_Ref == "W") { $Lon_Neg = "-"; }
$Lon_H = explode("/" ,$GPS['GPSLongitude']['0'])[0];
$Lon_M = explode("/" ,$GPS['GPSLongitude']['1'])[0];
$Lon_S = explode("/" ,$GPS['GPSLongitude']['2'])[0];
$Lon_S2 = explode("/" ,$GPS['GPSLongitude']['2'])[1];

$Lat = $Lat_H+($Lat_M/60)+(($Lat_S/$Lat_S2)/3600);
$Lon = $Lon_H+($Lon_M/60)+(($Lon_S/$Lon_S2)/3600);

return $Lat_Neg.$Lat.",".$Lon_Neg.$Lon;
}

JSON (from IMAGE EXIF):

"GPS": {
  "GPSLatitudeRef": "N",
  "GPSLatitude": [
    "22/1",
    "15/1",
    "1708/100"
  ],
  "GPSLongitudeRef": "W",
  "GPSLongitude": [
    "97/1",
    "52/1",
    "1882/100"
  ],
  "GPSAltitudeRef": "\u0000",
  "GPSAltitude": "9364/369",
  "GPSSpeedRef": "K",
  "GPSSpeed": "2203/12629",
  "GPSImgDirectionRef": "T",
  "GPSImgDirection": "52751/159",
  "GPSDestBearingRef": "T",
  "GPSDestBearing": "52751/159",
  "UndefinedTag:0x001F": "6625/828"
}
Dive answered 6/1, 2021 at 9:55 Comment(0)
M
-1

Umm the page you mention already gives you the coordinates in WGS84 and in Latitude Longitude format

Maud answered 15/6, 2009 at 12:11 Comment(1)
Yeah I know that but I just want a formula to get the latitude and longitude from the coordinates - WGS84 as you said format. Or a function in Php would be even nicer :)Aksoyn

© 2022 - 2024 — McMap. All rights reserved.