i am using google map.i have a simple example which is working fine.here is the code
function initialize() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(1, 103.849), 5);
map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));
map.addOverlay(new ELabel(new GLatLng(1, 103.980), 2, 'style11'));
map.setUIToDefault();}}
this above function is working well.Now i want to make it dynamic.like to set center i want to pass variable , like i place of this i will like to use this var center=”1, 103.849″ and i place of this line
map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, ‘style11’));
i want to use this line in variable….
here is my code which do not work.can anybody correct me?
function initialize() {
if (GBrowserIsCompatible()) {
var center = "1, 103.849";
var Locations = "map.addOverlay(new ELabel(new GLatLng(1, 103.849), 1, 'style11'));map.addOverlay(new ELabel(new GLatLng(1, 103.980), 2, 'style11'));";
var map = new GMap2(document.getElementById('map_canvas'));
map.setCenter(new GLatLng(center), 5);
+Locations +
map.setUIToDefault();
}
}
GLatLng takes two numbers as arguments, not a string. You need to do
I’m not sure what
+Locations+is designed to achieve. It’s a syntax error. Just use themap.addOverlay()line you had before.Note that Version 2 is deprecated and doesn’t have long to live. Use Version 3 of the API (which is rather different).