Last active
February 10, 2022 13:45
-
-
Save latuminggi/a0ea80c51710da047d70fb4a14106536 to your computer and use it in GitHub Desktop.
Convert Decimal degrees (DEC) to Degrees, minutes, and seconds (DMS) for Google Maps (bonus Embed URL)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function GMapsDECtoDMS($latitude, $longitude) { | |
// $latitude and $longitude must be a float value | |
// e.g. National Monument (-6.175413294875829, 106.82718181252345) | |
$latitudeDirection = $latitude < 0 ? 'S': 'N'; | |
$longitudeDirection = $longitude < 0 ? 'W': 'E'; | |
$latitudeNotation = $latitude < 0 ? '': ''; | |
$longitudeNotation = $longitude < 0 ? '': ''; | |
$lats = explode(".", $latitude); | |
$degLat = abs($lats[0]); | |
$tempLat = "0.".$lats[1]; | |
$tempLat = $tempLat * 3600; | |
$minLat = floor($tempLat / 60); | |
$secLat = round($tempLat - ($minLat * 60), 1); | |
$longs = explode(".", $longitude); | |
$degLong = abs($longs[0]); | |
$tempLong = "0.".$longs[1]; | |
$tempLong = $tempLong * 3600; | |
$minLong = floor($tempLong / 60); | |
$secLong = round($tempLong - ($minLong * 60), 1); | |
return sprintf('%s%s°%s\'%s"%s+%s%s°%s\'%s"%s', | |
$latitudeNotation, | |
$degLat, | |
$minLat, | |
$secLat, | |
$latitudeDirection, | |
$longitudeNotation, | |
$degLong, | |
$minLong, | |
$secLong, | |
$longitudeDirection | |
); | |
// return format: 6°10'31.5"S+106°49'37.9"E | |
// you can use to show on Google Maps like below | |
// https://www.google.com/maps/place/6°10'31.5"S+106°49'37.9"E | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!-- | |
Google Maps Embed URL | |
Strings to adjust in "src": | |
* Size | |
width= | |
height= | |
* Language (https://serpapi.com/google-languages) | |
hl= | |
en : english | |
id : bahasa indonesia | |
* Query search | |
q= | |
latitude,longitude | |
(or) | |
name+of+place | |
* Map type | |
t= | |
(blank) : standard map | |
k : satellite map | |
h : hybrid map | |
p : terrain map | |
* Zoom height | |
z= | |
15 : 200m | |
16 : 100m | |
17 : 50m | |
--> | |
<iframe | |
width="100%" | |
height="600px" | |
frameborder="0" | |
scrolling="no" | |
src="https://maps.google.com/maps?width=100%25&height=600&hl=id&q=-6.175413294875829,106.82718181252345&t=p&z=15&ie=UTF8&iwloc=B&output=embed" | |
/> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment