Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/293.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
从mysql数据库中检索要在javascript中用作值的值_Javascript_Php_Mysql_Database_Google Maps - Fatal编程技术网

从mysql数据库中检索要在javascript中用作值的值

从mysql数据库中检索要在javascript中用作值的值,javascript,php,mysql,database,google-maps,Javascript,Php,Mysql,Database,Google Maps,我正在制作一张地图,我想使用数据库中的值作为javascript中的坐标。请参阅下文: 我想通过从数据库中获取数据来更改经度和纬度的默认值,但我不知道如何更改 <html> <head> <meta http-equiv="content-type" content="text/html; charset=UTF-8" /> <title>Google Maps</title> <scrip

我正在制作一张地图,我想使用数据库中的值作为javascript中的坐标。请参阅下文:

我想通过从数据库中获取数据来更改经度和纬度的默认值,但我不知道如何更改

    <html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
    <title>Google Maps</title>
    <script src="http://maps.google.com/maps/api/js?sensor=false"     t      type="text/javascript"></script>
    <script type="text/javascript">
    function LatiPoint(options)
    {
        this.UserName = "";
        this.JobType = "";
        this.UserMood = "";
        this.Latitude = "";
        this.Longitude = "";
        this.Pic = "";
        this.Color = "red";
        this.OpenInfoWindowInitial = false;

        if (options != null)
        {
            this.UserName = options.UserName;
            this.JobType = options.JobType;
            this.UserMood = options.UserMood;
            this.Latitude = options.Latitude;
            this.Longitude = options.Longitude;
            this.Pic = options.Pic;
            this.Color = ( options.Color == null ? "red" : options.Color );
            this.OpenInfoWindowInitial = ( options.OpenInfoWindowInitial == null   ? false : options.OpenInfoWindowInitial );
        }
    }
    </script>

    <script type="text/javascript">
        var LatiPts = new Array();
        LatiPts[0] = new LatiPoint({UserName:'Dukot',JobType:'Balulang Cagayan     De Oro',UserMood:'drinking beer',Latitude:8.4542363,Longitude:124.63189769999997,Color:'yellow',OpenInfoWindowInitial:true,Pic:''});
        LatiPts[1] = new LatiPoint({UserName:'Alot',JobType:'Cagayan De Oro',UserMood:'with classmates',Latitude:8.458353831903118,Longitude:124.63627706511227,Color:'yellow',OpenInfoWindowInitial:true,});
        LatiPts[2] = new LatiPoint({UserName:'Lindongan',JobType:'SM Cagayan De Oro',UserMood:'feeling bored',Latitude:8.456188949479728,Longitude:124.62177167875973,Color:'yellow',OpenInfoWindowInitial:true,});
        LatiPts[3] = new LatiPoint({UserName:'Galal',JobType:'Carmen Cagayan De Oro',UserMood:'beer',Latitude:8.467607505884205,Longitude:124.62271581633297,Color:'yellow',OpenInfoWindowInitial:true,});
        LatiPts[4] = new LatiPoint({UserName:'Belen',JobType:'Cagayan De Oro',UserMood:'beer',Latitude:8.46332028090713,Longitude:124.63537584288326,Color:'yellow',OpenInfoWindowInitial:true,});


    </script>

    <script type="text/javascript">
    //<![CDATA[
        var infoWindows = [];
        var markers = [];

        // A function to create the marker and set up the event window
        function createMarker(map, point, title, icon) {
            var marker = new google.maps.Marker();
            marker.setMap(map);
            marker.setPosition(point);
            marker.setTitle(title);
            marker.setIcon(icon)

            google.maps.event.addListener(marker, 'click', function() {
                for (var i = 0; i < infoWindows.length; i++)
                    infoWindows[i].setZIndex(0);

                infoWindows[marker.counter].setZIndex(1);
                infoWindows[marker.counter].open(marker.getMap(), marker);
            });            

            return marker;
        }

        function createInfoWindow(html)
        {
            var infoWindow = new google.maps.InfoWindow();
            infoWindow.setContent(html);
            infoWindow.setZIndex(0);        

            return infoWindow;
        }

        function initialize() {

            // Create the Google Map
            var map = new google.maps.Map(document.getElementById("map"));
            map.setMapTypeId(google.maps.MapTypeId.ROADMAP);
            map.setCenter(new google.maps.LatLng(0,0));

            var bounds = new google.maps.LatLngBounds();

            for (var i = 0; i < LatiPts.length; i++) {
                var lpt = LatiPts[i];
                var point = new google.maps.LatLng(lpt.Latitude, lpt.Longitude);
                var html = "<span style='font-family:Arial;font-size:9pt'>";

                html += "<span style='font-size:12pt;font-weight:bold'>" + lpt.UserName + "</span><br />";
                html += lpt.UserMood.substring(0, 30) + "<br/>";
                html += lpt.JobType.substring(0, 30) + "<br/>";


                html += "</span>";

                var imgPath
                if(lpt.Pic != "") {
                    imgPath = lpt.Pic
                } else {
                    imgPath = "http://maps.gstatic.com/intl/en_ALL/mapfiles/marker.png"
                }
                //alert("imgPath = " + imgPath + " Pic: " + lpt.Pic)
                var icon = new google.maps.MarkerImage(imgPath);
                //icon.shadowSize = GSize.ZERO;

                var infoWindow = createInfoWindow(html);
                infoWindow.open();

                var marker = createMarker(map, point, lpt.UserName, icon);
                marker.setZIndex(0);
                marker.counter = i;


            if (LatiPts[i].OpenInfoWindowInitial)
                {
                    infoWindow.open(marker.getMap(), marker);
                }
                infoWindows.push(infoWindow);

                markers.push(marker);


                bounds.extend(point);

                            }

            map.setCenter(bounds.getCenter());
            map.fitBounds(bounds);

        }

        function handleNoFlash(code)
        {
            if ( code == GStreetviewPanorama.ErrorValues.FLASH_UNAVAILABLE )
                alert( 'You need flash player to view the panorama.' );
        }

        function convertLatLngToString(latlng)
        {
            var hour = parseInt(latlng)
            var min = parseInt((latlng - hour) * 60)
            var second = (((latlng - hour) * 60) - min) * 60

            return (hour + "&deg; " + min + "&#39; " + second.toFixed(2) + "&#34; ");
        }

    //]]>
    </script>    

    <style type="text/css">
        /*give the body height:100% so that its child
        elements can have percentage heights*/

        body{ margin:0;padding:0;height:100% }

        div.fullscreen{
            display:block;


            position:absolute;
            top:0;
            left:0;


            width:100%;
            height:100%;
            z-index: 9999;
            margin: 0;
            padding: 0;
            background: inherit;
        }

    </style>
</head>
<body onload="initialize()">
    <div id="map" class="fullscreen" style="width:100%; height:100%"></div>
    <div id="streetview" style="width: 650px; height: 400px; display: none;"></div>
    <noscript>
        <b>JavaScript must be enabled in order for you to use Google Maps.</b> 
    </noscript>

</body>
</html>

谷歌地图
功能纬度点(选项)
{
this.UserName=“”;
this.JobType=“”;
this.UserMood=“”;
这个。纬度=”;
这个。经度=”;
此。Pic=“”;
这个。Color=“red”;
this.OpenInfoWindowInitial=false;
如果(选项!=null)
{
this.UserName=options.UserName;
this.JobType=options.JobType;
this.UserMood=options.UserMood;
this.Latitude=options.Latitude;
this.Longitude=options.Longitude;
this.Pic=options.Pic;
this.Color=(options.Color==null?“红色”:options.Color);
this.OpenInfoWindowInitial=(options.OpenInfoWindowInitial==null?false:options.OpenInfoWindowInitial);
}
}
var LatiPts=新数组();
Latitpts[0]=新的纬度点({用户名:'Dukot',作业类型:'Balulang Cagayan De Oro',用户情绪:'Driving beer',纬度:8.4542363,经度:124.631897699997,颜色:'yellow',OpenInfoWindowInitial:true,图片:'});
纬度[1]=新纬度点({用户名:'Alot',作业类型:'Cagayan De Oro',用户情绪:'with atlasses',纬度:8.458353831903118,经度:124.6362770651127,颜色:'yellow',OpenInfoWindowInitial:true,});
Latitpts[2]=新的纬度点({用户名:'Lindongan',作业类型:'SM Cagayan De Oro',用户情绪:'feeling Obero',纬度:8.456188949479728,经度:124.62177167875973,颜色:'yellow',OpenInfoWindowInitial:true,});
Latitpts[3]=新的纬度点({用户名:'Galal',作业类型:'Carmen Cagayan De Oro',用户情绪:'beer',纬度:8.467607505884205,经度:124.62271581633297,颜色:'yellow',OpenInfoWindowInitial:true,});
纬度[4]=新纬度点({用户名:'Belen',作业类型:'Cagayan De Oro',用户情绪:'beer',纬度:8.46332028090713,经度:124.63537584288326,颜色:'yellow',OpenInfoWindowInitial:true,});
//
/*给孩子身高:100%让孩子
元素可以具有百分比高度*/
正文{边距:0;填充:0;高度:100%}
分区全屏{
显示:块;
位置:绝对位置;
排名:0;
左:0;
宽度:100%;
身高:100%;
z指数:9999;
保证金:0;
填充:0;
背景:继承;
}
必须启用JavaScript才能使用Google地图。

您可以执行以下操作: <?php /* read from database into variable $results*/ ?> this.UserName = "<?php echo $results; ?>"; this.UserName=“”;
希望有帮助:)

请展示您的PHP代码!你说你正在制作一个地图,但是代码只显示了一个函数。如果你能用完整的代码来完成这个问题,这将很容易帮助你。我试图发布所有的代码,但它不允许我发布。上面写着错误。无论如何,我想扩大我的问题。我想自定义纬度和经度的值,正如您在代码的最后两行中看到的。那里的值是我设置的默认值。我想要的是从数据库中获取一个值。数据库中的任何其他输入都应该被提取,并且应该进行循环以创建上面类似代码的新行(最后两行)。我希望我有道理:)谢谢!不要发布所有代码。请提供一个示例,演示您正在尝试执行的操作。在这里,我粘贴了整个代码。我希望现在清楚了。我需要你们的帮助:)和平!谢谢法鲁克。我要试试这个。:)但若我使用和javascript相同的页面从数据库中获取。人们可以看到我的登录详细信息,对吗?请问我该怎么解决这个问题?谢谢如果你想在JS中使用一些东西,它对用户来说是可见的,所以不要把JS中有价值的东西弄乱。不,它对用户不可见,它将在页面加载时在服务器上解析。用户只会看到这个。UserName=“User007”;可以你能告诉我如何从我的表中提取数据的全部代码吗。如果用户名有多个值呢?我想要的结果是使用数据库中的值在地图上创建一个标记。所以需要多个标记:)请帮助我:)阅读:多个用户名由while或for循环处理返回的数据行。所以,你一个接一个地得到它们,并对它们随心所欲:)