0

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();
        }
    }

1 Answer 1

1

GLatLng takes two numbers as arguments, not a string. You need to do

var centerlat = 1;
var centerlng = 103.849;
map.setCenter(new GLatLng(centerlat,centerlng), 5);

I'm not sure what +Locations+ is designed to achieve. It's a syntax error. Just use the map.addOverlay() line you had before.

map.addOverlay(new ELabel(new GLatLng(centerlat,centerlng), 2, 'style11'));

Note that Version 2 is deprecated and doesn't have long to live. Use Version 3 of the API (which is rather different).

Sign up to request clarification or add additional context in comments.

6 Comments

yes i am using version 3.yes i have fixed this point map.setCenter(new GLatLng(centerlat,centerlng), 5);....the issue is still exist in next point....i am pointing differect locations on googlemap what is why creating map.addOverlay dynamically for all records...for example if i have to show 50 points on map then we have to use 50 map.addOverlay...
i edit my code now...here is issue when i want more than one data on google me...actually i want to display all the search results user have searched
You are not using Version 3. GBrowserIsCompatible, GMap2 and GLatLng are all Version 2; and ELabel only works with Version 2.
Can any body help me what to use instead?i have html,css and js to create numbered markers on map.like 1,2,3 etc
@Methew: That's a different question. And there have already been a couple of SO questions on that too. See Google
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.