几天以来,我一次又一次地试图找到合适的地方,但没有任何运气。
我无法找到将map.panby ( x , y )
放在我的以下谷歌地图代码中的位置,以便将标记更多地放在右侧。
如果有人可以帮助我会很棒!
最佳
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(52.5200066, 13.404954);
var mapOptions = {
zoom: 6,
scrollwheel: false,
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
draggable: false,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.LEFT_CENTER
},
streetViewControl:false,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [
{
"featureType": "administrative.country",
"elementType": "geometry",
"stylers": [
{ "weight": 1.2 },
{ "color": "#dd4b39" }
]
},{
"featureType": "administrative",
"stylers": [
{ "visibility": "simplified" }
]
},{
"featureType": "administrative.country",
"stylers": [
{ "visibility": "on" }
]
},{
"featureType": "administrative.locality",
"stylers": [
{ "visibility": "on" }
]
}
]
}
map = new google.maps.Map(document.getElementById('user-map-canvas'), mapOptions);
}
function showAddress(address) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
} else {
alert("Adresse konnte aus folgendem Grund nicht gefunden werden: " + status);
}
google.maps.event.addListener(marker, 'click', function() { // Add a Click Listener to our marker
window.location='/freiwillige/?s=<?php echo $country ?>'; // URL to Link Marker to (i.e Google Places Listing)
});
});
}
jQuery(document).ready( function() { initialize(); showAddress('<?php echo $address ?>'); } );
</script>
答案 0 :(得分:0)
你应该能够在地图实例化之后的任何时候放置panby,所以在你给出的例子中:
map = new google.maps.Map(document.getElementById('user-map-canvas'), mapOptions);
map.panby(x, y);
应该完美地运作。
请注意,此功能平移地图,它不会相对于瓷砖移动标记,我认为这是你的意图吗?
编辑您应该能够在执行中的任何一点发出呼叫。因此,例如,在您的地理编码请求之后稍微抵消地图:
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
map.panby(x, y);
}
编辑好的,所以我已经根据我提到的更改修改了原始代码。试试这个:
<script type="text/javascript">
var geocoder;
var map;
function initialize() {
geocoder = new google.maps.Geocoder();
var mapOptions = {
zoom: 6,
scrollwheel: false,
navigationControl: false,
mapTypeControl: false,
scaleControl: false,
draggable: false,
zoomControl: true,
zoomControlOptions: {
style: google.maps.ZoomControlStyle.SMALL,
position: google.maps.ControlPosition.LEFT_CENTER
},
streetViewControl:false,
mapTypeId: google.maps.MapTypeId.ROADMAP,
styles: [
{
"featureType": "administrative.country",
"elementType": "geometry",
"stylers": [
{ "weight": 1.2 },
{ "color": "#dd4b39" }
]
},{
"featureType": "administrative",
"stylers": [
{ "visibility": "simplified" }
]
},{
"featureType": "administrative.country",
"stylers": [
{ "visibility": "on" }
]
},{
"featureType": "administrative.locality",
"stylers": [
{ "visibility": "on" }
]
}
]
}
map = new google.maps.Map(document.getElementById('user-map-canvas'), mapOptions);
}
function showAddress(address) {
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location
});
map.setCenter(results[0].geometry.location);
map.panby(x, y);
}
else
{
alert("Adresse konnte aus folgendem Grund nicht gefunden werden: " + status);
}
google.maps.event.addListener(marker, 'click', function() { // Add a Click Listener to our marker
window.location='/freiwillige/?s=<?php echo $country ?>'; // URL to Link Marker to (i.e Google Places Listing)
});
});
}
jQuery(document).ready( function() { initialize(); showAddress('<?php echo $address ?>'); } );
</script>
我删除了地图的原始居中(以及变量latlng,您不在其他任何地方使用它),然后在地理编码请求完成后居中并偏移。手指。交叉。
编辑如果panby仍无法正常工作,请参阅答案Here,但我看不到代码的任何问题。