I\'m using google maps. In my code i\'ve used setCenter() function. My problem is that marker is always located on top left corner of map area (not at the center). Please te
@phoenix24 answer actually helped me (whose own asnwer did not solve my problem btw). The correct arguments for setCenter is
map.setCenter({lat:LAT_VALUE, lng:LONG_VALUE});
Google Documentation
By the way if your variable are lat and lng the following code will work
map.setCenter({lat:lat, lng:lng});
This actually solved my very intricate problem so I thought I will post it here.
in your code, at line
map.setCenter(new GLatLng(lat, lon), 5);
the setCenter method takes just one parameter, for the lat:long location. Why are you passing two parameters there ?
I suggest you should change it to,
map.setCenter(new GLatLng(lat, lon));
For me above solutions didn't work then I tried
map.setCenter(new google.maps.LatLng(lat, lng));
and it worked as expected.
I searched and searched and finally found that ie needs to know the map size. Set the map size to match the div size.
map = new GMap2(document.getElementById("map_canvas2"), { size: new GSize(850, 600) });
<div id="map_canvas2" style="width: 850px; height: 600px">
</div>
function resize() {
var map_obj = document.getElementById("map_canvas");
/* map_obj.style.width = "500px";
map_obj.style.height = "225px";*/
if (map) {
map.checkResize();
map.panTo(new GLatLng(lat,lon));
}
}
<body onload="initialize()" onunload="GUnload()" onresize="resize()">
<div id="map_canvas" style="width: 100%; height: 100%">
</div>