You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm a beginner of Javascript and trying to use leaflet-realtime. From your library I replaced https://wanderdrone.appspot.com/ with my url and I try with php return like
it work fine. But as you know since php is server side language and can't get user's real geolocation. So I try with Javascript and trying many way to return from html5 built-in api navigator.geolocation.getCurrentPosition(callback,fail) like this
request.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
if(navigator.geolocation){
navigator.geolocation.getCurrentPosition(showLocation);
}else{
$('#location').html('Geolocation is not supported by this browser.');
}
});
function showLocation(position){
var latitude = position.coords.latitude;
var longitude = position.coords.longitude;
$.ajax({
type:'POST',
url:'response.php',
dataType: 'json',
data:'latitude='+latitude+'&longitude='+longitude,
success:function(msg){
if(msg){
msg = JSON.stringify(msg);
console.log(msg);
}else{
alert('Error');
}
}
});
}
</script>
Hi,
I'm a beginner of Javascript and trying to use leaflet-realtime. From your library I replaced https://wanderdrone.appspot.com/ with my url and I try with php return like
it work fine. But as you know since php is server side language and can't get user's real geolocation. So I try with Javascript and trying many way to return from html5 built-in api navigator.geolocation.getCurrentPosition(callback,fail) like this
request.php
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script> <script> $(document).ready(function(){ if(navigator.geolocation){ navigator.geolocation.getCurrentPosition(showLocation); }else{ $('#location').html('Geolocation is not supported by this browser.'); } }); function showLocation(position){ var latitude = position.coords.latitude; var longitude = position.coords.longitude; $.ajax({ type:'POST', url:'response.php', dataType: 'json', data:'latitude='+latitude+'&longitude='+longitude, success:function(msg){ if(msg){ msg = JSON.stringify(msg); console.log(msg); }else{ alert('Error'); } } }); } </script>response.php
if(!empty($_POST['latitude']) && !empty($_POST['longitude'])){
}
But leaflet-realtime show me this error
'leaflet-realtime.js:260 SyntaxError: Unexpected token < in JSON at position 2 undefined'
I have no idea how to return JSON string with Javascript. I also try with fetch but I can't get it. Could you please help me about this issue?
Htike Aung,
Web Developer,
The text was updated successfully, but these errors were encountered: