Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/466.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_Google Maps_Google Maps Api 3_Sidebar - Fatal编程技术网

Javascript 位置和侧边栏不会显示在谷歌地图中

Javascript 位置和侧边栏不会显示在谷歌地图中,javascript,google-maps,google-maps-api-3,sidebar,Javascript,Google Maps,Google Maps Api 3,Sidebar,我的代码没有在谷歌地图上显示边栏和标记,在输出中我只得到谷歌地图 <?php error_reporting(0); include('dbcon.php'); $result = mysql_query("SELECT address FROM markers"); $new_array = array(); while ($row = mysql_fetch_assoc($result)) { $new_array[] = $row['address']; } $add

我的代码没有在谷歌地图上显示边栏和标记,在输出中我只得到谷歌地图

<?php

error_reporting(0);
include('dbcon.php');
$result = mysql_query("SELECT address FROM markers");
$new_array = array();
while ($row = mysql_fetch_assoc($result)) {
    $new_array[] = $row['address'];  
}

$add_js = json_encode($new_array);

//print_r($add_js);

?>

<script type="text/javascript"> 

var side_bar_html = ""; 
var gmarkers = []; 
var map = null;

function initialize() {
    // create the map
    var myOptions = {
        zoom: 8,
        center: new google.maps.LatLng(28.6139, 77.2089),
        mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    // Add markers to the map
    var point = <?php echo $add_js ?>;
    function geocodeAddress(i) {
        geocoder.geocode({
            'address' : point[i]
        }, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                map.setCenter(results[0].geometry.location);
                createMarker(results[0].geometry.location, i);
            }
            else {
                alert('Geocode was not successful for the following reason: ' +
                    status);
            }
        });
        return marker;
    }
    document.getElementById("side_bar").innerHTML = side_bar_html;
}

var infowindow = new google.maps.InfoWindow({ 
    size: new google.maps.Size(150, 50)
});

function myclick(i) {
    google.maps.event.trigger(gmarkers[i], "click");
}

function createMarker(latlng, name, html) {
    var contentString = html;
    var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        icon : icon1,
    });

    //add info window

    google.maps.event.addListener(marker, 'mouseover', function() {
        marker.setIcon(icon2);
        infowindow.setContent(point[i]);
        infowindow.open(map, marker);
        title: 'Property!'
    });

    google.maps.event.addListener(marker, 'mouseout', function() {
        marker.setIcon(icon1);
        infowindow.setContent(point[i]); 
        infowindow.close(map, marker);
        title: 'Property!' 
    });

    //end of adding info window

    // save the info we need to use later for the side_bar
    gmarkers.push(marker);
    // add a line to the side_bar html
    side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length-1) + ')">' +
        name + '<\/a><br>';
}

</script> 

var side_bar_html=“”;
var gmarkers=[];
var-map=null;
函数初始化(){
//创建地图
变量myOptions={
缩放:8,
中心:新google.maps.LatLng(28.613977.2089),
mapTypeId:google.maps.mapTypeId.ROADMAP
}
map=new google.maps.map(document.getElementById(“map_canvas”),myOptions);
//向地图添加标记
var点=;
功能地理编码地址(i){
地理编码({
“地址”:点[i]
},功能(结果、状态){
if(status==google.maps.GeocoderStatus.OK){
map.setCenter(结果[0].geometry.location);
createMarker(结果[0]。geometry.location,i);
}
否则{
警报('地理代码未成功,原因如下:'+
地位);
}
});
返回标记;
}
document.getElementById(“side\u bar”).innerHTML=side\u bar\u html;
}
var infowindow=new google.maps.infowindow({
尺寸:新谷歌。地图。尺寸(150,50)
});
功能myclick(i){
google.maps.event.trigger(gmarkers[i],“点击”);
}
函数createMarker(latlng、name、html){
var contentString=html;
var marker=new google.maps.marker({
位置:latlng,
地图:地图,
图标:icon1,
});
//添加信息窗口
google.maps.event.addListener(标记'mouseover',函数(){
标记设置图标(icon2);
设置内容(点[i]);
信息窗口。打开(地图、标记);
标题:“财产!”
});
google.maps.event.addListener(标记'mouseout',函数(){
标记设置图标(icon1);
设置内容(点[i]);
信息窗口。关闭(地图、标记);
标题:“财产!”
});
//添加信息窗口结束
//保存我们以后需要用于侧栏的信息
G标记器。推(标记器);
//在侧栏html中添加一行
侧栏html+=''+
名称+“
”; }
我对这种编码概念非常陌生,大部分代码都是通过谷歌搜索得到的。我已经提供了我的大部分代码,但我没有找到问题所在


提前谢谢。

关于侧栏:您可以在对象(代码中的变量myOptions)中指定应该显示什么和不显示什么。

关于侧栏:您可以在对象(代码中的变量myOptions)中指定应该显示什么和不显示什么。

+1用于回答好的问题;-)<代码>geocodeAddress()在代码中的任何地方都不会被调用。也许您希望运行for循环来遍历您的点。这将为您提供标记和侧栏。好的问题为+1;-)<代码>geocodeAddress()在代码中的任何地方都不会被调用。也许您希望运行for循环来遍历您的点。这将为您提供标记和侧栏。