我爲我的網站使用yii2-google-maps-markers。 它工作正常。 我想創建一個搜索引擎,所以我想在顯示搜索結果後更改google map的中心值。 我可以更改中心位置,但所有制造商都被刪除。 如何通過使用指定地址的js而不需要刪除製造商來改變中心。 我的代碼如下:通過使用yii2-google-maps-markers設置Google地圖中心
view.php
<?php
echo GoogleMaps::widget([
'userLocations' => $locat,
'googleMapsUrlOptions' => [
'key' => Yii::$app->params['GOOGLE_API_KEY'],
],
'googleMapsOptions' => [
],
'wrapperHeight' => '350px',
]);
?>
和當前的解決方案
<script type="text/javascript">
// Run function after page loaded
document.addEventListener('DOMContentLoaded', function() {
show_map_theo_address("some where, America");
}, false);
// This is the minimum zoom level that we'll allow
function show_map_theo_address(address) {
var geocoder, vitri;
var minZoomLevel = 15;
geocoder = new google.maps.Geocoder();
if (geocoder) {
geocoder.geocode({
'address': address
}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (status != google.maps.GeocoderStatus.ZERO_RESULTS) {
vitri = results[0].geometry.location;
var map = new google.maps.Map(document.getElementById('map_canvas'), {
zoom: minZoomLevel,
center: new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng()),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
}
}
}
});
}
}
但它不工作。 請幫忙。
意味着什麼不行..你有錯誤(在瀏覽器控制檯檢查)或其他? – scaisEdge
沒有錯誤,但所有制造商都被刪除。我不想要這個。 – Sam