简体   繁体   English

为什么这个PHP不能与谷歌地图一起工作?

[英]why doesn't this php work with google maps?

I'm trying to figure out why this PHP script isn't creating the map I specify in the HTML. 我试图弄清楚为什么这个PHP脚本没有创建我在HTML中指定的地图。 any ideas? 有任何想法吗?

<!doctype html>

<html>
    <head>

        <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

        <style>

            html { height: 100% }
            body { height: 100%; margin: 0; padding: 0 }
            #map { height: 100% }

        </style>

        <script
        src="http://maps.googleapis.com/maps/api/js?sensor=false">

        </script>

        <?php
            $lat = $_POST['lat'];
            $long = $_POST['long'];

            echo "

        <script>

            function callMap() {

                var latlng = new google.maps.LatLng($lat, $long);"; ?>
                var options = {
                    zoom: 5,
                    center: latlng,
                    mapTypeId = google.maps.MapTypeId.TERRAIN

                };
                var map = new google.maps.Map(document.getElementById("map"),
                options);


            }

        </script>
    </head>
    <body onload="callMap()">
    <div id="map"></div>




    </body>

</html>

Your options declaration syntax is messed up: 您的options声明语法搞砸了:

var options = {
    zoom: 5,
    center: latlng,
    mapTypeId = google.maps.MapTypeId.TERRAIN // ERROR
};

Should be 应该

var options = {
    zoom: 5,
    center: latlng,
    mapTypeId: google.maps.MapTypeId.TERRAIN
};

你还错过了谷歌js链接上的一个括号。

I don't use PHP so I can't tell if there's anything wrong with that code. 我不使用PHP,所以我不知道该代码是否有任何问题。 If you removed the PHP and hardcoded lat/lon values, does the map work? 如果删除了PHP和硬编码的lat / lon值,地图是否有效? Maybe one problem could be just what values the form is posting with the latitude and longitude. 也许一个问题可能就是表格以纬度和经度发布的价值。 You're not doing any sort of validation to ensure they are within acceptable bounds, eg +90 to -90 for latitude and +180 to -180 for longitude. 您没有进行任何类型的验证以确保它们在可接受的范围内,例如纬度为+90到-90,经度为+80到-180。

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

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