I want to link my json result to the google map. I have a imei_number
in the database which is the password of the user. Once the user enter the right password(imei_number
in the database), the system will select the longitude and latitude of the imei_number
selected and later link it to the google map's longitude and latitude.
The HTML code is:
<form method="post" action="loginServer.php">
<label> Username: </label>
<input type = "text" maxlength = "20" name = "user" id= "user" />
<br />
<label> Password: </label>
<input type = "password" maxlength= "20" name="pass" id= "pass" />
<br />
<input type ="Button" onclick="" value="Clear" />
<input type = "Submit" value = "Login"id= "btn"/>
</p>
</form>
The Google map page is
<script type = "text/javascript">
function LoadMap(){
var mapEdit = {
zoom: 8,
center: new google.maps.LatLng($.getJSON('connect.php', function(data) {
$.each(data, function(key, val) {
$("ul").append(val.latitude);
});
});
,
$.getJSON('connect.php', function(data) {
$.each(data, function(key, val) {
$("ul").append(val.longitude);
});
});
),
mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map"), mapEdit);
var marker = new google.maps.Marker({
position: new google.maps.LatLng( $.getJSON('connect.php', function(data) {
$.each(data, function(key, val) {
$("ul").append(val.latitude);
});
});
,
$.getJSON('connect.php', function(data) {
$.each(data, function(key, val) {
$("ul").append(val.longitude);
});
});
),
map: map,
});
marker.addListener('click', function(){
infowindow.open(map, marker);
});
}
</script>
</head>
<body onload = "LoadMap()">
<div id="map" style="width: 400px; height: 500px;"></div>
The connect.php is
<?php
include 'linker.php';
$sql = "SELECT * FROM android_data WHERE $pass = 'imei_number'";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while($row = mysqli_fetch_array($result)) {
$data[] = $row;
$row["longitude"]);
$row["longitude"]. " - latitude: " . $row["latitude"]. "<br>";
}
} else {
echo "0 results";
}
echo json_encode($data);
mysqli_close($conn);
?>
The linker.php is
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "project_gps";
$user = $_POST['user'];
$pass = $_POST['pass'];
$user = stripcslashes($user);
$pass = stripcslashes($pass);
$conn = mysqli_connect($servername, $username, $password, $dbname);
$user = mysqli_real_escape_string($conn, $user);
$pass = mysqli_real_escape_string($conn, $pass);
if($conn){
echo "connected";
}
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
?>
But they are not all working. Please, what can I do?