Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/367.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 使用谷歌地图显示存储在数据库中的位置_Javascript_Html_Google Maps - Fatal编程技术网

Javascript 使用谷歌地图显示存储在数据库中的位置

Javascript 使用谷歌地图显示存储在数据库中的位置,javascript,html,google-maps,Javascript,Html,Google Maps,我在数据库中存储了一些位置及其经度和纬度 我的问题是如何使用谷歌地图显示这些位置 这是我的表格结构: 姓名:全球定位系统 属性:ID、经度、纬度 这是我的代码: <html> <!-- Inclusion de l'API Google Maps --> <script src="http://maps.google.com/maps/api/js?sensor=true"></script> <script>

我在数据库中存储了一些位置及其经度和纬度

我的问题是如何使用谷歌地图显示这些位置

这是我的表格结构:

姓名:全球定位系统

属性:ID、经度、纬度

这是我的代码:

   <html>      
  <!-- Inclusion de l'API Google Maps --> 
<script src="http://maps.google.com/maps/api/js?sensor=true"></script>
 <script>

   // On vérifie si le navigateur supporte la géolocalisation
   if(navigator.geolocation) {

function hasPosition(position) {
// Instanciation


 var point = new google.maps.LatLng(10.18153, 36.80649),

 // Ajustage des paramètres
 myOptions = {
  zoom: 15,
  center: point,
  mapTypeId: google.maps.MapTypeId.ROADMAP
 },

 // Envoi de la carte dans la div
 mapDiv = document.getElementById("mapDiv"),
 map = new google.maps.Map(mapDiv, myOptions),

 marker = new google.maps.Marker({
  position: point,
  map: map,
  // Texte du point
  title: "Vous êtes ici"
  });
}
navigator.geolocation.getCurrentPosition(hasPosition);
 }
 </script>
  <style>
    #mapDiv {
    /* Modifier la taille de la carte avec width et height */
width:600px;
height:450px;
border:1px solid #efefef;
margin:auto;
-moz-box-shadow:5px 5px 10px #000;
-webkit-box-shadow:5px 5px 10px #000;
 }
  </style>
   <!-- La carte sera chargée ici -->
   <div id="mapDiv"></div>
    </div>
    </html>

有什么想法吗???

希望此解决方案对您有所帮助

CSS

如果您没有lat和long,您可以使用下面的代码找到lat和long

function getLatLong(address) {

        var geo = new google.maps.Geocoder;
        geo.geocode({'address': address}, function(results, status) {

            if (status == google.maps.GeocoderStatus.OK) {

                var add = results[0].geometry.location;


                initialize(add.lat(), add.lng());

            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }

        });
    }

谢谢但我的问题是如何在谷歌地图脚本中使用存储在数据库中的经度和纬度!另一方面,每个ID都有自己的位置,所以在我的web应用程序中,当我选择ID并单击按钮跟踪时,脚本可以获得该ID的正确坐标并在地图中显示!!!希望您了解我的问题?单击Trace,调用此初始化函数,并在此函数中传递要显示的lat和long。您可以通过ajax调用和成功调用初始化函数使用id从数据库中获取lat long数据。
 <div id="map"></div>
NOTE: a = latitude , b = longitude

function initialize(a, b) {
        geocoder = new google.maps.Geocoder();
        var latlng = new google.maps.LatLng(a, b);
        var myOptions = {
            zoom: 13,
            center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP,
        };
        var map = new google.maps.Map(document.getElementById("map"), myOptions);
        var marker = new google.maps.Marker({
            map: map,
            position: latlng
        });
    }
function getLatLong(address) {

        var geo = new google.maps.Geocoder;
        geo.geocode({'address': address}, function(results, status) {

            if (status == google.maps.GeocoderStatus.OK) {

                var add = results[0].geometry.location;


                initialize(add.lat(), add.lng());

            } else {
                alert("Geocode was not successful for the following reason: " + status);
            }

        });
    }