【问题标题】:Simple google map using php [closed]使用php的简单谷歌地图[关闭]
【发布时间】:2014-10-27 06:49:20
【问题描述】:

Web 开发新手,想知道是否有一种简单的方法可以从表格中绘制简单的纬度和经度坐标并将它们呈现在地图上。我创建了一个简单的地点页面,它使用 php 从地点表中的每个存储地点绘制名称、地址等。我只想创建一个非常简单的地图,在 lat 和 lng 坐标处显示一个标记。对不起,如果这是一个愚蠢的问题。

【问题讨论】:

    标签: php google-maps google-maps-api-3


    【解决方案1】:

    这不是 PHP 问题。它使用 javascript。

    应该这样做:

    <script src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
    <script>
        var myMap;
        var myLatlng = new google.maps.LatLng(52.518903284520796,-1.450427753967233);
        function initialize() {
            var mapOptions = {
                zoom: 13,
                center: myLatlng,
                mapTypeId: google.maps.MapTypeId.ROADMAP  ,
                scrollwheel: false
            }
            myMap = new google.maps.Map(document.getElementById('map'), mapOptions);
            var marker = new google.maps.Marker({
                position: myLatlng,
                map: myMap,
                title: 'Name Of Business',
                icon: 'http://www.google.com/intl/en_us/mapfiles/ms/micons/red-dot.png'
            });
        }
        google.maps.event.addDomListener(window, 'load', initialize);
    </script>
    
    <div id="map" style="width:500px; height: 500px;">
    
    </div>
    

    只需将 myLatLng 变量更改为您想要的。

    如果您需要更多帮助,请参阅以下文档: https://developers.google.com/maps/documentation/javascript/tutorial#HelloWorld

    【讨论】:

    • 那么我是否将我的 php 变量 lat 和 lng 设置为 javascript 变量?
    • 感谢您的帮助。只是想知道将 php 变量 $lng 和 $lat 设置为我可以在您提供的代码中调用的 javascript 变量的最简单方法是什么?
    • 只需将其替换为: var myLatlng = new google.maps.LatLng(,);
    • 那些变量显然必须事先设置好
    • 太棒了!谢谢一百万!
    【解决方案2】:

    这很简单。这是 Google Maps API 的入门部分。您只需要注册一个 API 密钥,但它都写在那里。

    https://developers.google.com/maps/documentation/javascript/tutorial

    【讨论】:

    • 为什么需要 API 密钥才能使用 Google 地图?我没有
    • 如果您想使用谷歌地图 API 的所有功能而不仅仅是嵌入地图,那么您需要它。请参阅我发布的链接。
    【解决方案3】:

    这是一个例子

    <?php
    $url = "http://maps.google.com/maps/api/geocode/json?address=West+Bridgford&sensor=false&region=UK";
    $response = file_get_contents($url);
    $response = json_decode($response, true);
    
    //print_r($response);
    
    $lat = $response['results'][0]['geometry']['location']['lat'];
    $long = $response['results'][0]['geometry']['location']['lng'];
    
    echo "latitude: " . $lat . " longitude: " . $long;
    ?>
    

    【讨论】:

      猜你喜欢
      • 2013-03-16
      • 2016-05-22
      • 2011-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-08
      • 2011-03-25
      • 1970-01-01
      相关资源
      最近更新 更多