Search code examples
jquerygoogle-mapskmlgoogle-maps-markersjquery-gmap3

get markers from kmllayer with gmap3 jquery plugin?


I'm using jquery plugin gmap3 and am using a kmllayer. how can get markers from kml?. I need to filter the markers by regions


Solution

  • var klms = [{"url":"http:\/\/example.com\/points_in_a_kml_file.kml"}];
    
    if(klms){
        $.each(klms, function(i, klms){
            $('#map').gmap3({
                action: 'addKmlLayer',
                url: klms.url,
                options:{
                    suppressInfoWindows: true,
                    preserveViewport:  false
                }
            })
        })
    }
    

    "points_in_a_kml_file.kml":

    <?xml version="1.0" encoding="UTF-8"?>
    <Document>
    <Style id="style0">
        <IconStyle scale="0.181818">
            <Icon>
                <href>http://example.com/pin.png</href>
            </Icon>
        </IconStyle>
    </Style>
    <Folder>
        <name>pulau_weh_point</name>
        <Placemark>
            <name>Mama's</name>
            <description><![CDATA[Point's description]]></description>
            <Point>
                <coordinates>95.255227,5.875082,0.000000</coordinates>
            </Point>
            <styleUrl>#style0</styleUrl>
        </Placemark>
    </Folder>
    </Document>