I'm sure this is a stupidly simple question but I'm struggling with it :S
I want to offset my map center using panBy
as mentioned in this question but I'm not entirely sure where to place mapObject.panBy(0,30)
or if I need to change the bit that says mapObject
Here is my code so far:
function initialize()
{
var mapProp = {
center:new google.maps.LatLng<?php echo $entrylatlng;?>,
zoom:14,
scrollwheel: false,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap") ,mapProp);
var contentString =
if( gmapsstring.gmapaddresspostcode.length > 0 ) {
contentString += '<p>' + gmapsstring.gmapaddresspostcode + '</p>';
};
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var point = new google.maps.LatLng<?php echo $entrylatlng;?>;
var marker = new google.maps.Marker({
position: point,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
infowindow.open(map,marker);
}
google.maps.event.addDomListener(window, 'load', initialize);
Sorry for the reams of code, I'm not sure what needs to be included. Thanks for any help.
I'm sure this is a stupidly simple question but I'm struggling with it :S
I want to offset my map center using panBy
as mentioned in this question but I'm not entirely sure where to place mapObject.panBy(0,30)
or if I need to change the bit that says mapObject
Here is my code so far:
function initialize()
{
var mapProp = {
center:new google.maps.LatLng<?php echo $entrylatlng;?>,
zoom:14,
scrollwheel: false,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap") ,mapProp);
var contentString =
if( gmapsstring.gmapaddresspostcode.length > 0 ) {
contentString += '<p>' + gmapsstring.gmapaddresspostcode + '</p>';
};
var infowindow = new google.maps.InfoWindow({
content: contentString
});
var point = new google.maps.LatLng<?php echo $entrylatlng;?>;
var marker = new google.maps.Marker({
position: point,
map: map
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.open(map,marker);
});
infowindow.open(map,marker);
}
google.maps.event.addDomListener(window, 'load', initialize);
Sorry for the reams of code, I'm not sure what needs to be included. Thanks for any help.
Share Improve this question edited May 23, 2017 at 12:06 CommunityBot 11 silver badge asked Jul 29, 2013 at 18:58 XavXav 3072 gold badges4 silver badges12 bronze badges 1- 2 It seems like you pasted the initialize function twice. To keep track and a clean question you should maybe remove the duplicate, to allow others to quickly get an overview without having to read unnecesary code. – burnedikt Commented Jul 29, 2013 at 19:03
1 Answer
Reset to default 7Basically you can start panning directly after you initialized the map. So your initialize function might look like this:
function initialize(){
var mapProp = {
center: new google.maps.LatLng<?php echo $entrylatlng;?>,
zoom: 14,
scrollwheel: false,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("googleMap") ,mapProp);
// start panning
map.panBy(0, 30);
var contentString =
if( gmapsstring.gmapaddresspostcode.length > 0 ) {
contentString += '<p>' + gmapsstring.gmapaddresspostcode + '</p>';
};
/**
* the rest of your code goes here
* ...
*/
}