Geolocation submit to php script successful using geolocation cordova plugin in intel xdk

28 views
Skip to first unread message

ricardo gaynor

unread,
May 15, 2016, 8:38:17 PM5/15/16
to phonegap
when trying to submit it on the target device the request fail and this only fail for geolocation, i've ripped out the geolocation from the code and tried it and it works without geolocation on the target device but it wont work on the target device when submitting the coordinates. i alert the longitude and latitude and it show on the target device but it is not submitting although the variable exist for latitude and longitude. here is my javascript and php below, pleases help:

<script>

$(document).ready(function(){
$(’#buttonx’).click(function(){
navigator.geolocation.getCurrentPosition(function(pos){
var latitude = pos.coords.latitude;
var longitude = pos.coords.longitude;
var longitude1 = longitude;
var latitude1 = latitude;
var username = $(’#username’).val();
var password = $(’#password’).val();
var reportdetail = $(’#reportdetail’).val();

// alert(latitude);
// alert (latitude);
$.ajax({
type:‘POST’,
url:’http://192.168.1.6/pls/locationpg.php‘,
data:‘latitude=’+latitude+’&clongitude=’+longitude+’&username1=’+username+’&password1=’+password+’&reportdetail1=’+reportdetail,
success:function(msg){
if(msg){
$("#location").html(msg);
alert(longitude);
alert(latitude);
}else{
$("#location").html(‘Not Available’);
}
var username = $(’#username’).val(’’);
var password = $(’#password’).val(’’);
var reportdetail = $(’#reportdetail’).val(’’);
}

}).error(function(){
    $('#feedback1').text("");
}).complete(function(){
    $('#feedback2').text("");
}).success(function(){
    $('#feedback3').text("");
});

});
});
});

</script>



and my php here:



<?php
$con = new mysqli(“localhost”, “root”, “”, “pls”);
if ($con){
echo “connection successful”;
}else {
echo “connection isn’t successful”;
}
if (isset ($_POST[‘longitude’]) && isset($_POST[‘latitude’])){
$longitude = filter_input(INPUT_POST, ‘longitude’);
$latitude = filter_input(INPUT_POST, ‘latitude’);

$insert = mysqli_query($con, “INSERT INTO geolocation VALUES (’$latitude’, ‘$longitude’, ‘’)”);
if ($insert){
echo “data inserted successful”;
echo $lat.’<br>’.$long;
}else if (!$insert){
echo “data wasnt inserted successfully”;
}
}
?>

Reply all
Reply to author
Forward
0 new messages