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
Hi there,
There is an issue with role permissions that is being worked on at the moment.
If you are having trouble with access or permissions on regional forums please post here to get access: https://www.boards.ie/discussion/2058365403/you-do-not-have-permission-for-that#latest

Google maps API Query question

  • 03-01-2009 4:37pm
    #1
    Closed Accounts Posts: 603 ✭✭✭


    Hi there.
    Apologies if this is a stupid question but here goes.
    I wrote a simple javascript that plots an address on a google map using Geocoding function from the Google maps API.

    Ideally what I would like would to be able to plot multiple markers on a google map. You know the way you go to google maps and enter a search string like British airways, London, uk and you get multiple markers. Is there anyway to do this via the google maps api (through a javascript)?

    I would imagine that if it's possible, that you would get multiple LatLng variables returned in an array or something, then you simply plot them.

    Any help Greatly appreciated. Happy New year,
    S


Comments

  • Closed Accounts Posts: 30 Mr. Magoo


    Hi there.
    Apologies if this is a stupid question but here goes.
    I wrote a simple javascript that plots an address on a google map using Geocoding function from the Google maps API.

    Ideally what I would like would to be able to plot multiple markers on a google map. You know the way you go to google maps and enter a search string like British airways, London, uk and you get multiple markers. Is there anyway to do this via the google maps api (through a javascript)?

    I would imagine that if it's possible, that you would get multiple LatLng variables returned in an array or something, then you simply plot them.

    Any help Greatly appreciated. Happy New year,
    S

    I've never used the geocoding stuff so I can't comment on whether you can pass it multiple addresses at once but actually adding multiple points to the map is dead easy. You can pretty much do whatever you have done already to add one pin multiple times.

    The easiest thing to do is probably lash your points into a JSON array and return that to you JavaScript and just loop through it and add the points like that, might get a bit slow though if you have a lot of different map points.

    There's code I used before for adding multiple points from an XML doc. If that's any use to you I could dig it up for ya.

    Here's a chunk of code I've used in the past to add multiple points to the map, usually just in a loop.
    vPoint = new GLatLng(53.3396,-6.32006);
        
    vIcon = new GIcon(G_DEFAULT_ICON);
    vIcon.image =  'http://www.google.com/intl/en_us/mapfiles/ms/micons/blue-dot.png';
    
    vIcon.iconSize = new GSize(32, 32);
    	
    markerOptions = { icon:vIcon };
    	
    vMarker = new GMarker(vPoint, markerOptions);
    
    map.addOverlay(vMarker);
    


  • Registered Users, Registered Users 2 Posts: 21,611 ✭✭✭✭Sam Vimes


    yes you can do it. There's a url where you pass in an address and get back the geocode. Then on the map you can just pass in multiple points separated by commas. I can't remember the exact urls and i'm on the phone at the moment but i'll look them up tomorrow


  • Registered Users, Registered Users 2 Posts: 21,611 ✭✭✭✭Sam Vimes


    i think i misunderstood your question. i just thought you were trying to put more than one marker on a page but now i see you want to be able to search for something and get several results for the same string.

    tbh i don't think that capability is in the api. if i search for british airways london uk (http://maps.google.com/maps/geo?q=british+airways+london+uk&output=csv) i get a 602 unknown address error. what i think happens on the proper google maps is if the address you searched for isn't found it tries to find near matches and geocodes them. but again, i don't think that functionality has been made available on the api.

    you should join the api forum and ask there. they'd know better than us

    edit: you get a 610 invalid api key error if you click the link above because the request is coming from boards.ie but if you put it into the address bar you get a 602


  • Closed Accounts Posts: 603 ✭✭✭shamrock2004


    Thanks for the replies;
    I eventually hammered it out using the GLocalSearch function
    and then looped through the results results array to get all the lat and lng vars. Then, I created a new maker for each one and added a listener so that when you click it, you get the address in the openinfowindow popup! :)


Advertisement