简体   繁体   English

如何将数据库值获取到 javascript 谷歌地图中

[英]how to get database value into javascript google map

i know there is the same question like mine but i still don't understand...我知道有和我一样的问题,但我还是不明白......

i want to make a google map with value in my database there are 3 value in my database: name, lat, and lon.我想用我的数据库中的值制作一个谷歌地图,我的数据库中有 3 个值:名称、纬度和经度。

and i want to get this value and add this into my javascript.我想获得这个值并将其添加到我的 javascript 中。

here is my google map script (stil fresh from w3school) :这是我的谷歌地图脚本(仍然来自 w3school):

<script>

var myCenter=new google.maps.LatLng(51,508743,-0,12085);

function initialize()
{
var mapProp = {
  center:myCenter,
  zoom:5,
  mapTypeId:google.maps.MapTypeId.ROADMAP
  };

var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);

var marker=new google.maps.Marker({
  position:myCenter,
  });

marker.setMap(map);
}

google.maps.event.addDomListener(window, 'load', initialize);
</script>

i have read this question : Getting database values in Javascript variable dynamically .我读过这个问题: 在 Javascript 变量中动态获取数据库值

but still dont understand how it works, what do i need to add and what do i need to change.但仍然不明白它是如何工作的,我需要添加什么以及我需要改变什么。 please help请帮忙

In which language?用哪种语言?

In PHP you have to just use your variables with db table column values in place of long and lat.在 PHP 中,您只需将变量与 db 表列值一起使用,而不是 long 和 lat。

eg and例如和

var myCenter=new google.maps.LatLng(,); var myCenter=new google.maps.LatLng(,);

Let me know if you want the multiple maps with in the loop.如果您想要循环中的多个地图,请告诉我。

Vikash维卡什

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM