Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
(function ($) {
Drupal.behaviors.mjh_views_alter = {
attach: function(){
$("button.location-gmap-find-address-button").click(function(e){
e.preventDefault();
var address_parts = new Array();
$("fieldset#edit-" + $(this).val() + " .form-item input[type=text]," +
"fieldset#edit-" + $(this).val() + " .form-item select > option:selected").each(function(){
if (!$(this).hasClass('gmap-control') && $(this).val() != '') {
if($(this).is('option')) {
address_parts.push($(this).text());
} else {
address_parts.push($(this).val());
}
}
});
var address_string = address_parts.join(', ');
var gmap_id = $("fieldset#edit-" + $(this).val() + " .gmap-map").attr('id');
if (google.maps.version !== 'undefined') { // assume Google Maps API v3 as API v2 did not have this variable
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address_string}, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var m = Drupal.gmap.getMap(gmap_id);
m.locpick_coord = results[0].geometry.location;
m.change('locpickchange');
m.map.setCenter(results[0].geometry.location);
m.map.setZoom(14);
}
else {
alert(Drupal.t("Your address was not found."));
}
});
}
else {
var geocoder = new GClientGeocoder();
geocoder.reset(); // Clear the client-side cache
geocoder.getLatLng(address_string, function(point){
if (!point){
alert(Drupal.t("Your address was not found."));
}
else {
var m = Drupal.gmap.getMap(gmap_id);
m.locpick_coord = point;
m.change('locpickchange');
m.map.setCenter(point, 14);
}
});
}
});
}
}
})(jQuery);