PHP获取地图位置当前街道地址未出现

时间:2019-02-28 08:39:02

标签: php

我正在使用脚本获取纬度和经度,以便在加载页面后立即在地图上显示。该地图会出现,但它的位置显示为空,名称中仅带有逗号(,)而不是当前位置。 sreet的名称不会出现。该标记出现在世界地图的中间。

它适用于具有固定编号的职位,但必须适用于当前职位。

代码:

<div class="my-coloapse-body open"  id="my-coloapse-1" >
    <div class="map-section" >
        <div class="input-streename-row">
            <input id="streetname" type="text" name="name" class="" placeholder="όνομα δρόμου">
            <input name='longitude' id='longitude' type='hidden'/>
            <input name='latitude' id='latitude' type='hidden'/>

            <span class="relocate  ti-target " onclick="getMapLocation();"></span>
        </div>
        <div id="map"> </div>

        <?php $ITEMS = array(); //get_query("SELECT * FROM `pillars`"); ?> 

        <?php
        if (!filter_input(INPUT_GET, 'map-provider') == 'osm') {
            include("pillar-position-google.php");
        } else {
            include("pillar-position-osm.php");
        }
        $NOMALOCATION = 1;
        include(__DIR__ . "/../position-common.php");
        ?>
        <script>

            getMap('<?php echo $PILLAR["latitude"]; ?>', '<?php echo $PILLAR["longitude"]; ?>');

        </script>
    </div>
</div>

函数getmap:

//使用坐标获取地图

function getMap(latitude, longitude) {
    var mapOptions = {
        center: new google.maps.LatLng(0, 0),
        zoom: 20,
        maxZoom: 20,
        mapTypeId: google.maps.MapTypeId.ROADMAP,
        styles: [{
                featureType: "poi",
                elementType: "labels",
                stylers: [{ visibility: "off" }]
            },
            { "featureType": "all", "elementType": "all", "stylers": [{ "saturation": -100 }, { "gamma": 0.5 }] }
        ],
        mapTypeControl: true,
        streetViewControl: false
    };
    map = new google.maps.Map(document.getElementById("map"), mapOptions);
    locations.forEach(function(location) {
        marker = new google.maps.Marker({
            position: new google.maps.LatLng(location["lat"], location["lng"]),
            id: location["id"],
            icon: location["icon"],
            map: map
        });
        google.maps.event.addListener(marker, 'click', function(evt) {
            $.fancybox.open({
                src: '#dialogContent-' + this.id,
                type: 'inline',
                opts: {
                    afterShow: function(instance, current) {
                        console.info('done!');
                    }
                }
            });
            markers.push(marker);
        });
    });
    var latLong = new google.maps.LatLng(latitude, longitude);
    var marker = new google.maps.Marker({
        position: latLong,
        draggable: true,
    });
    marker.setMap(map);
    map.setZoom(20);
    map.setCenter(marker.getPosition());
    google.maps.event.addListener(marker, 'dragend', function() {
        $("#streetname").val("...");
        $.ajax({
            type: 'POST',
            url: '<?php echo APP_URL ?>get_address.php',
            data: {
                lat: marker.getPosition().lat,
                lng: marker.getPosition().lng,
            },
            success: function(data) {
                $("#streetname").val(data.trim());
            }
        });
        $("#latitude").val(marker.getPosition().lat);
        $("#longitude").val(marker.getPosition().lng);
    });
    $("#streetname").val("...");
    $.ajax({
        type: 'POST',
        url: '<?php echo APP_URL ?>get_address.php',
        data: {
            lat: marker.getPosition().lat,
            lng: marker.getPosition().lng,
        },
        success: function(data) {
            $("#streetname").val(data.trim());
        }
    });
    $("#latitude").val(marker.getPosition().lat);
    $("#longitude").val(marker.getPosition().lng);
}

编辑:

该页面似乎需要运行2个脚本。首先,它采用地图上的默认位置(0,0),如果我编辑一个固定位置,则它会在几秒钟后刷新当前位置(例如,雅典的纬度和经度)

function watchMapPosition() {

    return navigator.geolocation.watchPosition
    (onMapWatchSuccess, onMapError, { enableHighAccuracy: true });
}




// watchMapPosition();

getMapLocation();
</script>


    <script>
//  getMap( '37.94767073344734','23.734566048514125 ');
  </script>

chevron

0 个答案:

没有答案