I want to show my live location but the marker pin to everywhere but atlantic ocean
it use coordinate from mysql
heres my code
function initialize(){
var myLatLng = new google.maps.LatLng(37.27099968781691, 139.0884548336095);
var myOptions = {
zoom: 15,
center:myLatLng,
mapTypeId: google.maps.MapTypeId.TERRAIN
}
map = new google.maps.Map( document.getElementById('map'),myOptions);
<?php
$sql="select * from positions";
$query=mysqli_query($conn, $sql));
while($data=mysqli_fetch_array($query)){
?>
var marker= new google.maps.Marker({
position:new google.maps.LatLng(<?php echo $data['lat']; ?>, <?php echo $data['lon']; ?>),
map:map,
});
markers.push(marker);
<?php
}
?>
}
var markers=new Array();
var infowindows=new Array();
var refreshId2 = setInterval(function(){navigator.geolocation.getCurrentPosition(foundLocation, noLocation);}, 100);
function foundLocation(position) {
var lat2 = position.coords.latitude;
var lon2 = position.coords.longitude;
var uri = "saving point file.php";
$.ajax({
type: 'POST',
async: false,
dataType: "html",
url: uri,
data: "lat="+lat2+"&long="+lon2,
success: function(data) {
}
});
}
var refreshId = setInterval(function(){updatedata();}, 100);
function updatedata(){
var lat;
var long;
for(var i=0;i<markers.length;i++){
var uri = "lat's file.php";
$.ajax({
type: 'POST',
async: false,
dataType: "html",
url: uri,
data: "id="+i,
success: function(data) {
lat=data;
}
});
var uri = "lon's file.php";
$.ajax({
type: 'POST',
async: false,
dataType: "html",
url: uri,
data: "id="+i,
success: function(data) {
long = data;
}
});
var myLatLng = new google.maps.LatLng(lat, long);
markers[i].setPosition(myLatLng);
infowindows[i].setPosition(myLatLng);
}
}
lat's file.php and lon's file.php are the same, they selecting point from database
$id=$_POST['id'];
$sql="select * from positions";
$query=mysqli_query($conn, $sql));
$data=mysqli_fetch_array($query);
echo $data['lon']; /* echo $data['lat']; if latitude */
saving point file.php, basically saving current location to database
session_start();
$lat=$_POST['lat'];
$lon=$_POST['lon'];
$sql="update positions set lat='$lat', lon='$lon' where id='$_SESSION[id]'";
$query=mysqli_query($conn, $sql);
if the $data['lat'] = 37.26636473354969 and $data['lon'] = 139.082895335262 as the first point, then they will be updated to somewhere base my location because its a live loc code
and it also zooming at another place, not at the marker
how to fix it?
is it my code error or device error? i have my gps on and use data from my phone's hotspot which the gps also on.
thanks
question from:
https://stackoverflow.com/questions/65848694/google-map-marker-doesnt-at-the-current-location