Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
321 views
Welcome To Ask or Share your Answers For Others

1 Answer

@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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...