Offset google map center with panby

google-maps, javascript

Solution

Basically 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
  * ...
  */
}

Problem

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.

Original source

Related problems