لات طويل إلى دقائق وثواني؟
-
20-09-2019 - |
سؤال
تعطيني خرائط Google Lat وطول موقع في تدوين عشري مثل هذا:
38.203655,-76.113281
كيف يمكنني تحويلها إلى تنسيقات (درجات ، دقائق ، ثوان)
المحلول
38.203655 هي قيمة عشرية للدرجات. هناك 60 دقيقة هي درجة و 60 ثانية في الدقيقة (1 degree == 60 دقيقة == 3600s).
لذا ، خذ الجزء الكسري من القيمة ، أي 0.203655 ، وضربه مع 60 للحصول على دقائق ، أي 12.2193 ، أي 12 دقيقة ، ثم كرر الجزء الكسري من الدقائق ، أي 0.2193 = 13.158000 ثانية.
مثال في بيثون:
def deg_to_dms(deg):
d = int(deg)
md = abs(deg - d) * 60
m = int(md)
sd = (md - m) * 60
return [d, m, sd]
print deg_to_dms(38.203655)
print deg_to_dms(-76.113281)
نصائح أخرى
In case you need other geo-related functionality in JavaScript, you may use the following library
http://www.movable-type.co.uk/scripts/latlong.html
it provides the following functionality:
- DMS from/to decimal latitude/longitude conversions
- Distance calculations
- Bearing calculation
- Intersection point calcualtion
Python library that does the trick:
I think this will help you with the solution :
def deg_min_sec(self,degrees=0.0):
if type(degrees) != 'float':
try:
degrees = float(degrees)
except:
print '\nERROR: Could not convert %s to float.' % (type(degrees))
return 0
minutes = degrees % 1.0 * 60
seconds = minutes % 1.0 * 60
return (degrees, minutes, seconds)
لا تنتمي إلى StackOverflow