无法通过LAT长指出确切的位置



我创建了一个地图,以指示客户提供的地址的确切位置。我在地址上很长一段时间,但没有指出地图上的地图标记,我不知道为什么它没有指出任何人可以帮助我愉快的地方是我的代码

<?php
    $addresse    = $_POST['address'];
    $prepAddr    = str_replace(' ','+',$addresse);
    $geocode     = file_get_contents('https://maps.google.com/maps/api/geocode/json?address='.$prepAddr.'&sensor=false');
    $output      = json_decode($geocode);
    $latitude    = $output->results[0]->geometry->location->lat;
    $longitude   = $output->results[0]->geometry->location->lng;
?>
<div id="map" style="width:400px;height:400px;"></div>
<script>
function unick() {
var mapOptions = {
    center: new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>),
    zoom: 10,
    mapTypeId: google.maps.MapTypeId.satellite
}
var map = new google.maps.Map(document.getElementById("map"), mapOptions);
}
</script>

您必须在地图上添加标记,例如:

var map = new google.maps.Map(document.getElementById("map"), mapOptions);    
var latLng = new google.maps.LatLng(<?php echo $latitude; ?>, <?php echo $longitude; ?>);
var marker = new google.maps.Marker({
    position: latLng,
    map: map,
    title: 'You are here'
    label: 'You are here'
});

编辑:添加了标题和标签属性。有关更多信息,请参见Google Maps API参考

最新更新