Maps - JS API Interactive search

ExpressionEngine Code





{exp:reinos_maps:html_header}

{exp:reinos_maps:map
    center:address="heerde"
    width="100%"
}

{exp:reinos_maps:html_footer}

$(function(){
    $('form').submit(function(){
        //geocode address
        REINOS_MAPS.api('geocode', {
            address : $('input[name="address"]').val(),
            callback : function(result, type){

                //remove old markers
                REINOS_MAPS.api('removeMarkers', {
                    mapID : 'reinos_map_1'
                });

                //parse result
                result = $.parseJSON(result);

                //add marker
                REINOS_MAPS.api('addMarker', {
                    mapID : 'reinos_map_1',
                    lat: result[0].latitude,
                    lng: result[0].longitude,
                    title: result[0].city
                });

                //Fit the map
                REINOS_MAPS.api('fitMap', {
                    mapID : 'reinos_map_1',
                    zoomLevel : 11
                });

            }
        });
        return false;
    });
});