Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Kasper Dyrvig 246 posts 379 karma points
    Dec 29, 2010 @ 15:27
    Kasper Dyrvig
    0

    Seeking a clever way to do Google Maps

    Hi

    I'm tring to do a Google Map with multiple markers on. The coordinates is stored in child nodes. I have actually made it work, but it seems very ineffective... can you help me improve it?

     

    My "old" code is:

       function initialize() {
          <xsl:for-each select="$currentPage/* [@isDoc and umbracoNaviHide != '1' and stayGoogleMaps != '']">
            var <xsl:value-of select="umbraco.library:TruncateString(@nodeName, '3', position())"/> = new google.maps.LatLng(<xsl:value-of select="stayGoogleMaps"/>);
          </xsl:for-each>
    var LatLng = new google.maps.LatLng(<xsl:value-of select="$currentPage/destinationMaps"/>);
         
    var myOptions = {
            zoom: 12,
            mapTypeControl: true,
            mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
            center: LatLng,
            navigationControl: true,
            mapTypeId: google.maps.MapTypeId.ROADMAP };
          var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
          <xsl:for-each select="$currentPage/* [@isDoc and umbracoNaviHide != '1' and stayGoogleMaps != '']">
            var marker = new google.maps.Marker({ position: <xsl:value-of select="umbraco.library:TruncateString(@nodeName, '3', position())"/>, map: map, title: &#34;<xsl:value-of select="@nodeName"/>&#34; });
          </xsl:for-each>
        }

    All the TruncateString's is to make the markers unique - but I don't know much about the Google Maps API so if someone has experience with that, it is also welcome :-)

    Thank you! (I use Umbraco 4.5.2)

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Dec 29, 2010 @ 16:14
    Ismail Mayat
    1

    there is a datatype to add gecodes http://our.umbraco.org/projects/backoffice-extensions/google-maps-datatype to a document see also Tim has done a google map package see http://our.umbraco.org/projects/backoffice-extensions/locator-package

    Regards

    Ismail

  • Kasper Dyrvig 246 posts 379 karma points
    Dec 30, 2010 @ 13:00
    Kasper Dyrvig
    0

    I have tried those, but they don't really fill out my need and wishes. So if anyone has a suggestion for a solution I'm listening!

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 30, 2010 @ 13:43
    Jan Skovgaard
    0

    Could you be a bit more specific about your need? In your post you write that you need to have multiple markers. Isn't that what Tim's package is giving you? :-)

    /Jan

  • Kasper Dyrvig 246 posts 379 karma points
    Dec 30, 2010 @ 14:28
    Kasper Dyrvig
    0

    Well, yes - but I think I have solved it myself.

    My xslt now looks like this:

    function initialize() { var latlng0 = new google.maps.LatLng(<xsl:value-of select="$currentPage/destinationMaps"/>);
    <xsl:for-each select="$currentPage/* [@isDoc and umbracoNaviHide != '1' and stayGoogleMaps != '']">
    <xsl:text>var latlng</xsl:text>
    <xsl:value-of select="position()"/>
    <xsl:text> = new google.maps.LatLng(</xsl:text>
    <xsl:value-of select="umbraco.library:Replace(stayGoogleMaps, ' ', '')"/>
    <xsl:text>);</xsl:text>
    </xsl:for-each>
    var myOptions = { zoom: 12, mapTypeControl: true, mapTypeControlOptions: { style: google.maps.MapTypeControlStyle.DROPDOWN_MENU },
    navigationControl: true, center: latlng0, mapTypeId: google.maps.MapTypeId.ROADMAP };
    var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    <xsl:for-each select="$currentPage/* [@isDoc and umbracoNaviHide != '1' and stayGoogleMaps != '']">
    <xsl:text>var marker = new google.maps.Marker({position: latlng</xsl:text>
    <xsl:value-of select="position()"/>
    <xsl:text>, map: map, title: &#34;</xsl:text>
    <xsl:value-of select="stayName"/>
    <xsl:text>&#34;});</xsl:text>
    </xsl:for-each>
    }

    It is much like what i posted yesterday, but more clean.

    What I ask about now is: This code seems to me to be a bit ineffective. Is there a way to optimize it? E.g. fewer lookups... but how?!?

    Thanks for your suggestions so far!

  • Ismail Mayat 4511 posts 10092 karma points MVP 2x admin c-trib
    Dec 30, 2010 @ 14:31
    Ismail Mayat
    1

    why not make use of tims excellent control its .net and works? I have in the past done it with xslt and javascript but its too much monkeying around just cleaner to use Tims control which is a nice wrapper around .net google library

    Regards

    Ismail

  • Kasper Dyrvig 246 posts 379 karma points
    Jan 03, 2011 @ 14:08
    Kasper Dyrvig
    0

    Thanks for your advises. :)

Please Sign in or register to post replies

Write your reply to:

Draft