I'm changing the center point on a google map by either two dropdown fields, or a search textbox and button. For each of these events I need to geocode the input and recenter the map. I tried to put all three events into one function so I can reuse the code, but I can't get it to work. When I click on the dropdown, it tries to geocode. Any idea how I can split this up?
Code:
jQuery('#input_13, #input_6_34, #map_change_button').bind('change click',
function() {
var geocoder = new GClientGeocoder();
var address;
if ( !jQuery("#map_search").val() ) {
address = jQuery("#input_13 option:selected").text() + ", " +
jQuery("#input_6_34 option:selected").text();
}
else {
address = jQuery("#map_search").val();
}
if ( geocoder ) {
geocoder.getLatLng(
address,
function(point) {
if ( !point ) {
alert(address + " not found");
} else {
map.setCenter(point);
marker.setPoint(point);
marker.show();
map.setZoom(13);
//jQuery("input#wp_geo_latitude").val(point.lat());
//jQuery("input#wp_geo_longitude").val(point.lng());
}
}
);
}
return false;
});