Skip to content Skip to sidebar Skip to footer

How To Pass Parameters To Google Maps Initmap In Xslt?

I'm trying to get the position by getting the latitude and longitude from an xml document, through an xslt stylesheet. I made xslt variables which return the correct latitude and l

Solution 1:

I think you need to change your Javascript code to have a function you can call to create the appropriate map and marker, so outside of any grouping you put

<script>functionshowMap(targetElement, location) {
              var map = new google.maps.Map(targetElement, { zoom: 15, center: location });
              var marker = new google.maps.Marker({
                position: location, 
                map: map
              });
            }
            </script>

then inside of your grouping you use

<ahref="#"onclick="showMap(document.getElementById('map'), {{ lat: {GEOCode/Latitude}, lng: {GEOCode/Longitude} }}); return false;">Street View</a>

that should solve the problem I think, in terms of interaction of XSLT and generated script code in an HTML document.

I don't know whether it would be easier/faster to not use new google.maps.Map each time the function is called and instead perhaps only move the center and the marker (or delete the existing marker and create a new) in an initially created map, but here is how you would implement that first script block instead:

<script>var map = null;
            var marker = null;

            functionshowMap(targetElement, location) {
              if (map != null) {
                  map.setCenter(location);
                  marker.setPosition(location);
              }
              else {
                  map = new google.maps.Map(targetElement, { zoom: 15, center: location });
                  marker = new google.maps.Marker({
                    position: location, 
                    map: map
                  });
              }
            }
            </script>

Post a Comment for "How To Pass Parameters To Google Maps Initmap In Xslt?"