Получить данные о местоположении с устройства при загрузке страницы - PullRequest
0 голосов
/ 30 апреля 2020

Я хочу использовать javascript из Praytimes.org , и я хочу получить данные о местоположении от устройства во время загрузки страницы и передать их как широта и лонг , как показано ниже

var times = prayTimes.getTimes(date, [lat,long], +6);
Пример страницы следующий.
<!DOCTYPE html>
<html>
<head>
	<title> Daily Prayer Timetable </title>
	<style>
		body, td, th {font-family: verdana; font-size: 12px; color: #404040;}
		#timetable {border-width: 1px; border-style: outset; border-collapse: collapse; border-color: gray; width: 9em;}
		#timetable td, #timetable th {border-width: 1px; border-spacing: 1px; padding: 2px 4px; border-style: inset; border-color: #CCCCCC;}
		#timetable th {color:black; text-align: center; font-weight: bold; background-color: #F8F7F4;}
	</style>
</head>

<body>


<script type="text/javascript" src="../PrayTimes.js"></script>

<br>
<p align="center">Jessore,Bangladesh<p>
<div align="center" id="table"></div>

<script type="text/javascript">
	
	var date = new Date(); // today
	var times = prayTimes.getTimes(date, [lat,long], +6);
	var list = ['Fajr', 'Sunrise', 'Dhuhr', 'Asr', 'Maghrib', 'Isha', 'Midnight'];

	var html = '<table id="timetable">';
	html += '<tr><th colspan="2">'+ date.toLocaleDateString()+ '</th></tr>';
	for(var i in list)	{
		html += '<tr><td>'+ list[i]+ '</td>';
		html += '<td>'+ times[list[i].toLowerCase()]+ '</td></tr>';
	}
	html += '</table>';
	document.getElementById('table').innerHTML = html;

</script>

</body>
</html>

1 Ответ

0 голосов
/ 01 мая 2020

Короткая демка

var latitude, longitude; // keep a variable to store lat, long for future use
navigator.geolocation.getCurrentPosition(showCoordinate);

function showCoordinate(rawPosition){
    latitude = rawPosition.coords.latitute;
    longitude = rawPosition.coords.longitude;
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...