Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Loading Google Maps Markers Dynamically

Options
  • 10-01-2008 9:20am
    #1
    Registered Users Posts: 3,401 ✭✭✭


    Hi,

    Has anyone successfully done this?

    The problem is if you load the google maps at the start in the javascript initialize function, you cannot call variables or functions within that initialize function?

    I would like to run the inner function addmarker using ajax but cant seem to find a way of doing this?

    I've tried placing the google code within the page i.e. after the map div but this is returning an error from IE?

    http://www.ratemypub.ie/template/county.php?countyid=10

    Thanks Again
    Gary


Comments

  • Registered Users Posts: 413 ✭✭ianhobo


    Could you accurately explain what you want to happen?

    You would probably need a div, and use javascript innerHTML to add an new link marker, then you would most likely have to call the google map load() funtion, which I don't think you are using,

    but if you explain in detail what you want to happen that would help


  • Registered Users Posts: 3,401 ✭✭✭randombar


    Hi Ian,
    Sorry to be annoying you again, anyways what I want my code to do is

    1 - the page loads with the first 20 pubs, their corresponding locations are added to the map (through ajax) and the new boundary is set.

    2 - when the user clicks "a" or "next" the next 20 pubs load up, the map is cleared and the 20 new markers are added and the new boundary is set.

    Could you explain the use of innerHTML? My ajax is currently returning a function
    map.clearOverlays();clearBounds();addsmallmappoint
    
    (53.3614, -6.27405,"<a href=\"http://www.ratemypub.ie/Dublin/Phoenix-Bar-(Bohemian-F.c.)/\">Phoenix Bar
    
     (Bohemian F.c.)</a><br>Type: Sports<br>Average Rating: 4.00342");
    


  • Registered Users Posts: 413 ✭✭ianhobo


    ok, first, and something that I think is a very important point, is regarding all the sql you have on your page!!! (Was this all there before? I don't remember seeing it before? )

    You are giving far too much away about your implementation!!! This is a PERFECT example of when to put code into an external js file. A hacker would have great fun with all this info! have you blocked "insert"? ANd is your database called "pub/s" by any anychance?

    What I would do is this i replace all of this sql with a javascript function call which will hide what your doing....
    <a href="javascript:;" onmousedown="showPubList('WHERE `countyid`=\'10\' AND  `pubname` LIKE \'B&#37;\' ORDER BY `pub`.`pubname` ASC'), showPubLoc('WHERE `countyid`=\'10\' AND pubname  LIKE \'B%\'  ORDER BY `pub`.`pubname` ASC');">B</a>
    <a href="javascript:;" onmousedown="showPubList('WHERE `countyid`=\'10\' AND  `pubname` LIKE \'C%\' ORDER BY `pub`.`pubname` ASC'), showPubLoc('WHERE `countyid`=\'10\' AND pubname  LIKE \'C%\' ORDER BY `pub`. `pubname` ASC');">C</a>
    

    every statement is the same exxcept for the two letters which is the link has been clciked. Similar to one of my previous posts, give each anchor a name parameter, so for link A, it would be:
    <a name="A" href="javascript:showLink(this)">A</a>
    

    the function showLink() would be your sql statment, then jsut add in this.name at each palce you require:
    showList(linkToShow)
    {
      var linkName = linkToShow;
      sql =  " WHERE `countyid`=\'10\' AND  `pubname` LIKE \' " + linkName + "    
                %\' ORDER BY `pub`.`pubname` ASC'), showPubLoc('WHERE   
                `countyid`=\'10\' AND pubname  LIKE \' " + linkName + " %\' ORDER 
                 BY `pub`. `pubname` ASC');
     
                /*Now call you showPubList function*/
               showPubList(sql);
    }
    

    Again, you code will be much neater


  • Registered Users Posts: 3,401 ✭✭✭randombar


    That's a very nice piece of code all right, makes things a lot nicer!

    Will definitely have to do a bit more thinking in that!

    EDIT:

    YESSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

    Ian hobo and musician, I def owe the two of ye a couple of pints! Savage Stuff!!

    Also how do I block my js file from prying eyes?


  • Registered Users Posts: 413 ✭✭ianhobo


    Because javascript is client side, I don't think you can completely hide it.
    Moving it to external just makes it more difficult.
    It could potentially be cached in temp internet files, directly typing in the filename would result in a download or a view, but basically the browser will have to access the file on the server, so the server will have to serve it!!!

    The only to completely hide it would be to implement a server side solution

    Where do we stand now with everything else? im getting confused between the two threads


  • Advertisement
  • Registered Users Posts: 3,401 ✭✭✭randombar


    Hi Ian,

    Google maps is now sorted, I realized you can define the functions outside the initialize function.

    I'm going to start sorting out my javascript now tidying it up into one file and using

    onload()

    and

    var elem = document.getElementById("myelement")
    if (elem) {
    //proceed
    }

    to sort it all out.

    Good to know about the removal of the query too, will take a bit of work as some of my queries are pretty large! i.e latebar=1 AND wheelchairaccess=1 . . . . .

    Where you based by de way, definitely owe ya a pint and could pick your brian about a few more things too!


  • Registered Users Posts: 413 ✭✭ianhobo


    Cool, glad its sorted.

    I live in Blanch and work in leopardstown

    Pick away..... :)


  • Registered Users Posts: 3,401 ✭✭✭randombar


    cool I owe ya a pint in the galloping green some evening so!

    nice commute!

    instead of passing varialbles in like so showLoc(1,2,A,4,5,1,1,0,1,0,0); and so on is there a neater way?


  • Registered Users Posts: 413 ✭✭ianhobo


    which part is that for?


  • Registered Users Posts: 3,401 ✭✭✭randombar


    Like you were saying about this:

    <a name="A" href="javascript:showLink(this)">A</a>

    The thing is I'm trying to use the same code for the search page which would need a lot more variables rather than just the letter?

    eg

    javascript:showLink(this,1,2,3,cork,1,0,1,0,1,0,1)


  • Advertisement
  • Registered Users Posts: 413 ✭✭ianhobo


    well my idea was that you would click the link, this would call the javascript script function, and allow your sql to be correctly formed for the specific link that was clicked.

    I dont think using it that way for multiple parameters would work with your sql, you would need another function, or else to modify your current sql statments.

    For the searching stuff, a different way might be required, or else try and design one common way which would suit both methods, but I don't think this is it though (the current way).

    What are the possible search option, and how are they to be selected by the user? is it a pre defined list? or just a text box?


  • Registered Users Posts: 3,401 ✭✭✭randombar


    Hi,

    It's a prefdefinied list you can see here:
    http://www.ratemypub.ie/template/find.php

    Some variables are 1 or 0 and others are text.

    I like the idea of one common way which is why I was using the $query, was wondering about the security issues of it all right!


Advertisement