Dynamically populated google maps sidebar

前端 未结 1 1543
情歌与酒
情歌与酒 2021-01-06 15:36

I\'ve been using the code from this V3 example to set up a links bar that dynamically populates when different category filters are selected, but have two problems at the mo

相关标签:
1条回答
  • 2021-01-06 16:15

    The reason your links are not working is that you are defining your my_click and makeSidebar functions inside of your mapInit function and so they are not available outside of the scope of mapInit. Simply move them outside of mapInit and everything should just work.

    As for the load event ... what you are looking for is the addDomListener method of google.maps.event. Simply use

    google.maps.event.addDomListener(window, 'load', name_of_your_inital_function);
    // e. g. google.maps.event.addDomListener(window, 'load', mapInit);
    

    Finally; notta bene ... don't do this:

    var image = [];
    image['attraction'] = 'data'; 
    image['food'] = 'more data';
    

    Arrays are not meant to be used as hashes in Javascript. Use objects for dictionaries / hashes instead -- it's what you are actually doing (Array "subclasses" Object) and it will make it easier for others to use your code (and save you from headaches down the line).

    var image = {};
    image['attraction'] = 'data'; 
    image['food'] = 'more data';
    
    0 讨论(0)
提交回复
热议问题