Plot Your Members on a Map [EXPERIMENTAL - not officially supported]

Last post 02-03-2012, 1:36 AM by DotCreativity. 18 replies.
Sort Posts:
  •  11-18-2010, 5:24 PM 20583

    Plot Your Members on a Map [EXPERIMENTAL - not officially supported]

     

     

     

    The following customizations allows you to publish a map of your members on your website.

    To use Google Maps on your Wild Apricot site, you will need the following:

    1. A Google Maps API Key: These are free to obtain, all you need is a Google account, and the URL of the site you want to use the map on (your free Wild Apricot domain or your custom domain. Click here to get your free API key.

    2. A public-facing member directory: You need a member directory added somewhere to you site that is not in a restricted access section (though it can be a hidden page). This member directory needs to at least show a name in the first column and an address (with city) in the second column.

    3. The page ID of your member directory: You can find out how to get the page ID here: Identifying page id

    You can insert the map on any page (including restricted access sections), though this will not work on pages like the member directory because the code contains too many characters for the description box. The code you need to insert is below (see Inserting HTML or JavaScript), you need to modify it by replace GOOGLE_API_KEY with your Google API key, next to mapParameters.site replace abc.cloverpad.org with your site url, next to mapParameters.memberDirectoryPageId replace 123456 with your member directory page ID, and next to centerViewAddress replace Ontario with the initial location you want to map to center on (city or state).

    Insert the following code into your page using the HTML button ( see Inserting HTML http://help.wildapricot.com/display/DOC/Inserting+HTML+or+JavaScript  )
     
    <div style="margin-bottom: 5px; height: 25px;"><input style="font-size: 16px; vertical-align: middle;" id="addressToFind" value=""> <input style="vertical-align: middle;" onclick="showAddress(document.getElementById('addressToFind').value);" value="Find address" type="button"></div>
    <div style="width: 660px; height: 650px;" id="map">Loading...</div>
    <div style="width: 660px; height: 300px;" id="pano">&nbsp;</div>
    <script type="text/javascript" src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=GOOGLE_API_KEY">
    </script><script type="text/javascript">
    var mapParameters =
    {
        site: 'abc.cloverpad.org',
        memberDirectoryPageId: 123456,
        centerViewAddress: 'Ontario',
        centerViewZoom: 13,
        enableStreetView: false
    };

    var map;
    var geocoder = null;
    var panoView = null;
    var addressMarker = null;
    var markers = [];

    function getColumnValue(member, column)
    {
        if (!member[column] || !member[column][0] || !member[column][0].v)
        {
            return '';
        }

        return member[column][0].v;
    }


    function placeMarker(member)
    {
         var name = getColumnValue(member, 'c1');
         var address = getColumnValue(member, 'c2');

         if (!address)
         {
             return;
         }

         geocoder.getLatLng(
                    address,
                    function(point)
                    {
                       if (!point)
                       {
                            return;
                       }
                       else
                       {
                            var marker = new GMarker(point);
                            map.addOverlay(marker);
                            GEvent.addListener(
                                 marker,
                                 "click",
                                 function()
                                 {
                                        marker.openInfoWindowHtml("<div style='display:block; height: 40px; width: 290px; text-align:center;'><h3>" + name + "<\/h3>" + address + "<\/div>");

                                        if (mapParameters.enableStreetView)
                                        {
                                            panoView.setLocationAndPOV (point);
                                        }
                                 });

                            markers.push(marker);
                       }
                    }
               );

    }

    function placeMarkers(json)
    {
       var outputHtml = [];

       for (var i = 0; i < json.members[0].length; i++)
       {
           placeMarker(json.members[0][i]);
       }
    }

    function memberDirectoryDataLoaded(executor)
    {
       var customMemberList = BonaPage.$('customMemberList');
       var response = executor.get_responseData();
       var regex = new RegExp("<JsonStructure>(.+)<\/JsonStructure>", "gi");
       var jsonText = regex.exec(response)[1];

       var json = eval("(" + jsonText + ")");

       placeMarkers(json);
    }

    function load()
    {
           if (GBrowserIsCompatible())
           {
                map = new GMap2(document.getElementById("map"));

                map.addControl(new GLargeMapControl());
                map.addControl(new GMapTypeControl());

                panoView = new GStreetviewPanorama(document.getElementById("pano"));

                geocoder = new GClientGeocoder();

                geocoder.getLatLng(
                    mapParameters.centerViewAddress,
                    function(point)
                    {
                          map.setCenter(point, mapParameters.centerViewZoom);
                    });
           }

           document.getElementById('addressToFind').value = mapParameters.centerViewAddress;
           document.getElementById('pano').style.display = mapParameters.enableStreetView ? 'block' : 'none';


           BonaPage.webRequest({
              url: 'http://' + mapParameters.site + '/Content/Members/MemberDirectory/MemberDirectoryWebService.asmx/LoadMembers?memberDirectoryPageId=' + mapParameters.memberDirectoryPageId,
              completedCallback: memberDirectoryDataLoaded
           });
    }

    load();

    function showAddress(address)
         {
            if (geocoder)
            {
               geocoder.getLatLng(
                    address,
                    function(point)
                    {
                       if (!point)
                       {
                            alert("Address " + address + " not found");
                       }
                       else
                       {
                            map.setCenter(point, 16);

                            if (addressMarker)
                            {
                                map.removeOverlay(addressMarker);
                            }

                            addressMarker = new GMarker(point);
                            map.addOverlay(addressMarker);
                            addressMarker.openInfoWindowHtml(address);

                            if (mapParameters.enableStreetView)
                            {
                                  panoView.setLocationAndPOV (point);
                            }
                       }
                    }
               );
          }
    }

    </script>
     

    Frank | User Experience Designer
    Wild Apricot
  •  11-29-2010, 11:57 AM 20678 in reply to 20583

    Re: Plot Your Members on a Map

    I am having trouble making this work.  Any help or direction appreciated
  •  11-29-2010, 3:58 PM 20683 in reply to 20678

    Re: Plot Your Members on a Map

    Could you elaborate on how far you did get? Or what error/problem you did encounter?
    Frank | User Experience Designer
    Wild Apricot
  •  12-03-2010, 10:07 AM 20744 in reply to 20683

    Re: Plot Your Members on a Map

    Well I did everything as you said but my members are not mapping anything.  It just shows a map.

     

    Can you help?

  •  12-03-2010, 3:58 PM 20752 in reply to 20744

    Re: Plot Your Members on a Map

    Could you send me your website address and mention the page your are using as the member directory to support@wildapricot.com and put 'attn:frank' in the subject line?

    Frank | User Experience Designer
    Wild Apricot
  •  12-03-2010, 11:27 PM 20759 in reply to 20752

    Re: Plot Your Members on a Map

    Will do right now. 

     

    Thank you - you guys are AWESOME!

  •  01-02-2011, 10:06 PM 20978 in reply to 20583

    Re: Plot Your Members on a Map

    I have tried doing this several times, including putting in my own API number - but my page just comes back with the Loading block and doesn't show a map. 

    I'm a bit confused about exactly what I have to change in terms of the code including the API number. I understand about the rest of the parameters.

    Could you please take a look at my site and give me some feedback.

    Thanks.   http://wisconsinflowergrowers.wildapricot.org/

  •  01-02-2011, 10:26 PM 20979 in reply to 20978

    Re: Plot Your Members on a Map

    Well, I finally got the map to show on http://wisconsinflowergrowers.wildapricot.org. However I'm confused about how it ties in to the member directory - I know i've put some names in but can't figure out how to find them back and then how to connect it.  I'll keep working when I have more time.

    Thanks for whatever quick suggestions you can give me. 

     So far I am liking everything I see.

  •  03-25-2011, 11:08 AM 22003 in reply to 20583

    • kchayka is not online. Last active: 07-19-2011, 10:01 PM kchayka
    • Top 200 Contributor
    • Joined about 1 year ago
    • Posts 11

    Re: Plot Your Members on a Map

    I'm getting some very inconsistent results with this. The map shows up OK but only some points are plotted. I can't figure out why some do and some don't. Maybe you can see something.

    http://www.personalchefscooperative.com/google-maps-test

    I added the address fields (city, state, postal code) in the 3rd column (hidden on the directory list page via CSS) and changed the JavaScript accordingly. All members should have that info in their account.

    directory page ID=960647

    Something else is I'd like the map marker popup to include a link to the individual member's profile page. I tried adding a link to the <h3> element in the pop-up but it just caused a JS error for 'no element' or something like that. The link should be <a href="http://www.personalchefscooperative.com/Content/Members/MemberPublicProfile.aspx?pageId=960647&memberId=###">

    Where do I get the value for ###?

    If we can get these 2 things worked out, especially not showing all the markers, then this will be a great addition to the site.

     

    thanks

  •  03-28-2011, 10:15 AM 22023 in reply to 20683

    Re: Plot Your Members on a Map

    I'm having the same problem ... when I asked Dimitri about it, the chief apricot told me to post here.  Can/would you take a look? 

     

     

    From: Wild Apricot Support [mailto:support@wildapricot.com]
    Sent: Monday, March 28, 2011 8:55 AM
    To: Barron, Joshua
    Subject: [184-151DD16C-E1FF] Google Maps API

     

    Joshua, I would suggest to post this to the forum.

    Cheers,

    Denys
    Wild Apricot:
    Member Management Magic
    Web software for small associations and non-profits

     


    From: joshua.barron@ttu.edu
    Sent: Sat, 26 Mar 2011 16:35:15 -0400
    To: Technical Support
    Subject: Google Maps API


    followed these instructions precisely, but still just get "loading …"
    Directory PageID = 981231
    Map Page located at:
    http://www.associationofdeansanddirectors.com/membermap

    What am I doing wrong?

  •  03-28-2011, 9:35 PM 22030 in reply to 22023

    • kchayka is not online. Last active: 07-19-2011, 10:01 PM kchayka
    • Top 200 Contributor
    • Joined about 1 year ago
    • Posts 11

    Re: Plot Your Members on a Map

    Directory PageID = 981231
    Map Page located at: http://www.associationofdeansanddirectors.com/membermap

    I think these may be incorrect. The PageID is the number on the <body> tag. View the HTML source of the member directory page, it shows:
    <body id="PAGEID_509041"...> so I think PageID should be 509041

    Maybe that will fix your problem, though it doesn't help mine.

    Can anyone tell me why not all of the markers are placed on my map? 126 members and I'm lucky if a dozen markers are placed. http://www.personalchefscooperative.com/google-maps-test

  •  04-08-2011, 6:18 PM 22137 in reply to 22030

    • kchayka is not online. Last active: 07-19-2011, 10:01 PM kchayka
    • Top 200 Contributor
    • Joined about 1 year ago
    • Posts 11

    Re: Plot Your Members on a Map

    OK, I think I'm getting this now, though I'm not sure how to "fix" it yet.

    I made the assumption that the "address" Frank mentioned in the code sample consisted of the fields in the 2nd column, concatenated. That was a false assumption. The code as supplied only uses the first field in that column to plot the marker. I would like to use the concatenated address fields (city, state, zip) so the marker plots the member's location, but show a different field from the directory in the pop-up, along with a link to the member's profile page.

    I guess I have to figure out how to do that now. The map from the other working example will surely help, but I do have questions on extracting particular bits of info from the directory db.

    For example, if I have 3 fields in column 3 (c3), what is the syntax for getting the 2nd field value? What is the syntax for the "bottom row" value? How can I directly request the "Postal Code" value, regardless of what column or row it is in? The answers to these questions will help me get this map working the way I'd like.

     

    Thanks for your assistance on this

  •  04-11-2011, 9:10 AM 22151 in reply to 22137

    Re: Plot Your Members on a Map

    Unfortunately these customizations are provided mostly 'as-is' so we don't modify/expand to beyond what is originally posted. That being said, I do understand your thinking and this is something that will become easier and supported once we introduce an official API for access to membership data (see http://community.wildapricot.com/thread/6821.aspx
    Frank | User Experience Designer
    Wild Apricot
  •  04-13-2011, 8:27 AM 22167 in reply to 22137

    Re: Plot Your Members on a Map

    Hi there, my colleague Vanya managed to find some time and look into this, here's his reply, I hope this helps you to move forward!
    ===== 
    "...[in the sample code above] the method getColumnValue returns only first value from column, but user can actually setup up to 3 fields in one column. In this particular case they selected Postal code for the first field and Province for second. So Google was only using the postal code. 
    I added two new functions to their Javsacript code [on page http://www.personalchefscooperative.com/google-maps-test ]: getColumnValue1 and getColumnValue2 and redefinded var address like
    var address = getColumnValue(member, 'c3') + ' ' + getColumnValue1(member, 'c3') + ' ' + getColumnValue2(member, 'c3'); (see method placeMarker)
    This site doesn't use third field in this column - but they can set it up to display City. This would make the search more precise.
    Another question was about MemberID. They can use for this value column 4 and define new var memberId = getColumnValue(member, 'c4') and use it in the popup window (tootip for point). They can set this column to have width 1% and it will not be shown on the list of members.

    And one last point. In method placeMarker they define var services = getColumnValue(member, 'c2');
    They don't use it currently, but if they decide to use it, they should be aware of that currently column 2 is used for Logo. And services are in bottom row (c5)."
     ======
    I hope this helps - if you are able to debug it, I would appreciate if you could share your final code and comments on this thread.

    Dmitry Buterin, Chief Apricot
  •  04-13-2011, 8:46 AM 22168 in reply to 22167

    • ivan is not online. Last active: 04-24-2012, 5:12 AM ivan
    • Not Ranked
    • Joined about 5 years ago
    • Zelenograd
    • Posts 2

    Re: Plot Your Members on a Map

    I just wanted to show these two functions to use second and third fields in a column. You can use them in the same way as function getColumnValue:

    function getColumnValue1(member, column)
    {
        if (!member[column] || !member[column][1] || !member[column][1].v)
        {
            return '';
        }

        return member[column][1].v;
    }

    function getColumnValue2(member, column)
    {
        if (!member[column] || !member[column][2] || !member[column][2].v)
        {
            return '';
        }

        return member[column][2].v;
    }

    (As mentioned above, getColumnValue get value of first field of column.)


    Ivan Rudakov, Snowy Apricot
  •  07-15-2011, 3:07 PM 23170 in reply to 20583

    • pollockk is not online. Last active: 05-17-2012, 7:33 PM pollockk
    • Top 150 Contributor
    • Joined about 10 months ago
    • Posts 15

    Re: Plot Your Members on a Map [EXPERIMENTAL - not officially supported]

    Frank - thanks for posting this code.

     

    i have created a hidden page on my site with a 2 column table i cut and pasted from excel with name in the first col and a postal code in the second column.

    i have a hidden page in our members only section with your html code in it.  i have my google id in and a page id (i could not find the page id on source code of my hidden directory page - i had to get the page id from the frame source with the directory table in it).

    on my hidden, members only page, i can see the map but no markers show up.

    Any suggestions?

     

    Kim

     

  •  07-20-2011, 9:34 PM 23205 in reply to 23170

    • pollockk is not online. Last active: 05-17-2012, 7:33 PM pollockk
    • Top 150 Contributor
    • Joined about 10 months ago
    • Posts 15

    Re: Plot Your Members on a Map [EXPERIMENTAL - not officially supported]

    Got it working - but only for subset of our 2000 members.  any suggestions on how to get entire database loaded?

     

    thanks...

  •  07-21-2011, 9:58 AM 23209 in reply to 23205

    Re: Plot Your Members on a Map [EXPERIMENTAL - not officially supported]

    Hi Kim,

    Google Maps has a limit on the number of Geocoding requests per day (2,500 requests per IP per day) as well as a rate limit - so requests that come in too quickly result in blocking.

    You will need to limit the rate requests are made with a timeout function, for example something like this:

     

    setTimeout(placeMarker(json.members[0][i]),500);

     

    You may want to consider using static maps rather than dynamic maps - it's a lot less complicated - see:http://community.wildapricot.com/22704/ShowThread.aspx


    DotCreativity Web Design Services
    http://www.dotcreativity.com
    Email: ideas@dotcreativity.com
  •  02-03-2012, 1:36 AM 24874 in reply to 22023

    Re: Plot Your Members on a Map

    Hello Everyone.

    If you are interested in either Google Maps integration or Proximity Searches, please get in contact with me to discuss your needs.

    The team at dotCreativity Design & Development Services can get all your members to load quickly up on an interactive Google Map, as well as provide proximity searches using a zip code or address.

    We have set up a demo for you to try here:


    You can contact us here: http://dotcreativity.com/contact-us/

    DotCreativity Web Design Services
    http://www.dotcreativity.com
    Email: ideas@dotcreativity.com
View as RSS news feed in XML
Membership Software - Wild Apricot