I am able to get the lat/lng coordinates, but somehow the system sets the center point of the map to (0,0). Would anyone be able to point me in the right direction for how to get the right lat/lng to become my center points?
The url where I am testing this is here:
http://www.comehike.com/hikes/hike_carpool.php?hike_id=125
Thank you,
Alex
just looked at your code:
map is set to (0,0) because you defined
lat, lngso, looks like you rely on lat, lng changing in ajax callback function, but it is asynchronous, so when browser gets tolatandlngin 99.99% cases will be 0, and only after some time (depending on network etc.) they will be changed, but it will be after map is built… Otherwise you have to create your map in callback function:shortly, you have to be sure lat and lng are defined as you need before map creation… This way it should work. Alternatively you can create map with center in (0,0) or somewhere else, but predefined, and then in ajax callback use
map.setCenter( center_latlng );also you do not create markers… your callback has
you define center_latlng value, but do not use it.. instead you put
markerdefined outside of callback to your markers array. Should be something like:EDIT: Took a look at your last implementation:
that function creates
mapin global scope, that’s not good until you really need it to be global. I updated my code above, so I would return map in that function (have a look). Otherwise, if you really need map to be global (meaning that something else could use it), then I would prefer another way (was shortly told above too): create map with center anywhere, then set its center in ajax callback. This way you will be sure that map is created as soon as possible, and you won’t get in trouble with “null” value (again if it is used outside initialize method, of even out of ajax callback: