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 tell me how to resolve it?
My piece of code is
lat = 46.437857; lon = -113.466797; marker = new GMarker(new GLatLng(lat, lon)); var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(20, 40)); map.addControl(new GLargeMapControl3D(), topRight); map.setCenter(new GLatLng(lat, lon), 5); map.addOverlay(marker);
The required elements for referencing from Google Maps are: Map publisher (Year of publication) Title of map section, Sheet number or tile, scale. Available at: DOI or URL (Accessed: date).
@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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With