Search code examples
google-mapskmlgoogle-earthofbiz

How to use KML file in Google Maps for OFBiz?


I'm trying to use KML file in Google Maps in OFBiz framework for a web application.I'm inputing the co-ordinates value in a array(list). So, how can i begin using Kml file in Google Maps??

I have inserted code of google maps in .ftl file

function initialize() {
        var map;
        var bounds = new google.maps.LatLngBounds();
        var mapOptions = {
            mapTypeId: 'satellite'
        };

        // Display a map on the page
        map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
        map.setTilt(45);

        // Multiple Markers
        var markers = [
            ['London Eye, London', 51.503454,-0.119562],
            ['Palace of Westminster, London', 51.499633,-0.124755]
        ];

        // Info Window Content
        var infoWindowContent = [
            ['<div class="info_content">' +
            '<h3>London Eye</h3>' +
            '<p>The London Eye is a giant Ferris wheel situated on the banks of the River Thames. The entire structure is 135 metres (443 ft) tall and the wheel has a diameter of 120 metres (394 ft).</p>' +        '</div>'],
            ['<div class="info_content">' +
            '<h3>Palace of Westminster</h3>' +
            '<p>The Palace of Westminster is the meeting place of the House of Commons and the House of Lords, the two houses of the Parliament of the United Kingdom. Commonly known as the Houses of Parliament after its tenants.</p>' +
            '</div>']
        ];

        // Display multiple markers on a map
        var infoWindow = new google.maps.InfoWindow(), marker, i;
        var infoWindow1 = [];

        for( i = 0; i < farmerCropList.length; i++ ) {
            var position = new google.maps.LatLng(farmerCropList[i].latitude, farmerCropList[i].longitude);
            bounds.extend(position);
            marker = new google.maps.Marker({
                position: position,
                map: map,
                title: farmerCropList[i].farmerCropId
            });

            infoWindow1[i] = new google.maps.InfoWindow({
                  content: '<div style="padding:5px;width:100%;height:auto;">' +
                                        '<div style="padding:5px;width:400px;font-size:16px;text-align:left">Farmer Name : '+(farmerCropList[i].firstName + farmerCropList[i].lastName)+'</div>'+
                                        '</div>'
              });



            var lastOpen = -1;
             google.maps.event.addListener(marker, 'click', (function(marker, i) {
                    if (lastOpen > -1) {
                        infoWindow1[lastOpen].close();
                    }
                    return function(){
                    infoWindow1[i].open(map, marker);
                    }
                    lastOpen = i;
            })(marker, i));


            map.fitBounds(bounds);
        }

        var boundsListener = google.maps.event.addListener((map), 'bounds_changed', function(event) {
            this.setZoom(15);
            google.maps.event.removeListener(boundsListener);
        });

        google.maps.event.addDomListener(window, 'load', initialize);

    }

Solution

  • You can use a KmlLayer

    see this google developer sample

    https://developers.google.com/maps/documentation/javascript/examples/layer-kml