douyanpeng0748 2017-01-04 12:21
浏览 25

谷歌地图上的标记使用Mysql,Php,Javascript

I have San Andreas map http://prntscr.com/drd9pz i add some markers using fallow code:

var burgInfoWindow = new google.maps.InfoWindow({
content: '<h3>Burg</h3><p>Ovo je mesto gde se igraci cesto okupljaju i zajedno jedu burgere.</p>'
});
var burgMarker = new google.maps.Marker({
    position: SanMap.getLatLngFromPos(1195.3125,-925.78125),
    map: map,
    icon: 'https://wiki.sa-mp.com/wroot/images2/0/0e/Icon_10.gif'
});
google.maps.event.addListener(burgMarker, 'click', function() {
    map.setCenter(burgMarker.position);
    burgInfoWindow.open(map,burgMarker);
});
    //Uncomment to show an alert with the position when you click on the map
 google.maps.event.addListener(map, 'click', function(event) {
        var pos = SanMap.getPosFromLatLng(event.latLng);
        alert(pos.x + "," + pos.y);
    });

Now i want to add markers with location from MySQL base like markers for house,so i take X,Y location of that house from my DB http://prntscr.com/drdaf8 and load X,Y and try to create markers but not work,this is code for that:

<?php
    $kuca=mysqli_query($conn,"SELECT * FROM kuce WHERE `kId` > 0");
    while($row = mysqli_fetch_array($kuca))
    {
        $x = $row['kUlazX'];
        $y = $row['kUlazY'];
        echo        
        "<script>
        var houseInfoWindow = new google.maps.InfoWindow({
        content: '<h3>Kuca</h3><p>Ovo je mesto gde igraci zive.</p>'
        });

        var houseMarker = new google.maps.Marker({
        position: SanMap.getLatLngFromPos($x,$y),
        map: map,
        icon: 'https://wiki.sa-mp.com/wroot/images2/b/b6/Icon_31.gif'});

        google.maps.event.addListener(houseMarker, 'click', function() {
        map.setCenter(houseMarker.position);
        houseInfoWindow.open(map,houseMarker); </script>";
    }

    ?> 
  • 写回答

1条回答 默认 最新

  • doumi7854 2017-01-04 12:35
    关注

    How your logic works? I don't know. But you have missed }) this.

    Please change

    houseInfoWindow.open(map,houseMarker); </script>";
    

    Into

    houseInfoWindow.open(map,houseMarker);}) </script>";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)