Drupal.gmap.addHandler('locpick_latitude',function(elem) { var obj = this; obj.bind("init", function() { if (elem.value != '') { obj.vars.latitude = toLatLng(elem.value); obj.locpick_coord = new GLatLng(obj.vars.latitude, obj.vars.longitude); } else { obj.locpick_coord = null; obj.locpick_invalid = true; } }); var binding = obj.bind("locpickchange", function() { if (obj.locpick_coord) { elem.value = obj.locpick_coord.lat(); } else { elem.value = ''; } }); $(elem).unbind("change"); $(elem).change(function() { if (elem.value != '') { if (obj.locpick_coord) { obj.locpick_coord = new GLatLng(toLatLng(elem.value), obj.locpick_coord.lng()); obj.change('locpickchange', binding); } else { obj.locpick_coord = new GLatLng(toLatLng(elem.value), 0.0); } } else { obj.change('locpickremove', -1); } }); }); Drupal.gmap.addHandler('locpick_longitude', function(elem) { var obj = this; obj.bind("init", function() { if (elem.value != '') { obj.vars.longitude = toLatLng(elem.value); obj.locpick_coord = new GLatLng(obj.vars.latitude, obj.vars.longitude); } else { obj.locpick_invalid = true; } }); var binding = obj.bind("locpickchange", function() { if (obj.locpick_coord) { elem.value = obj.locpick_coord.lng(); } else { elem.value = ''; } }); $(elem).unbind("change"); $(elem).change(function() { if (elem.value != '') { if (obj.locpick_coord) { obj.locpick_coord = new GLatLng(obj.locpick_coord.lat(), toLatLng(elem.value)); obj.change('locpickchange', binding); } else { obj.locpick_coord = new GLatLng(0.0, toLatLng(elem.value)); } } else { obj.change('locpickremove', -1); } }); }); function toLatLng(string) { if(!isNaN(string)) { return string; } regex = /^([+-]?)(\d+)(?:\xC2\xB0|\xA1|°)\s*(?:(\d+)[\'′]\s*)?(?:([\d.]+)["″]\s*)?([NSEWO])?$/; matches = regex.exec(string); if(matches) { degrees = matches[2] ? parseFloat(matches[2]) : 0; minutes = (matches[3]) ? parseFloat(matches[3]) : 0; seconds = (matches[4]) ? parseFloat(matches[4]) : 0; negative = (matches[5]) && (matches[5] == 'S' || (matches[5] == 'W' || matches[5] == 'O')); if (matches[1] == '-') { negative = !negative; } dd = (negative ? -1 : 1) * (degrees + (minutes/60) + (seconds/60/60)); return dd; } alert("Les coordonnées n'ont pas pu être converties en format décimal.\n Veuillez respecter le format +/- 47° 13' 05\" N/S/E/O"); return ''; }