Index: addresses/addresses.module
===================================================================
144a145,172
>     # PB:2011/01/17 Add lat and lan to get map position
>     $items['lat'] = array(
>       'type' => 'varchar',
>       'length' => 16,
>       'title' => t('Latitude'),
>       'description' => t('The latitude'),
>       'default' => '',
>       'display' => ADDRESSES_FIELD_SHOW,
>       'theme' => array(
>         'plain' => t('The latitude.'),
>         'hcard' => t('An hcard/vcard representation of the latitude.'),
>       ),
>     );
>     
>     $items['lon'] = array(
>       'type' => 'varchar',
>       'length' => 16,
>       'title' => t('Longitude'),
>       'description' => t('The longitude'),
>       'default' => '',
>       'display' => ADDRESSES_FIELD_SHOW,
>       'theme' => array(
>         'plain' => t('The longitude.'),
>         'hcard' => t('An hcard/vcard representation of the longitude.'),
>       ),
>     );
>     # PB:2011/01/17 Add lat and lan to get map position END
>     
Index: addresses/addresses.settings.inc
===================================================================
141a142,168
>   # PB:2011/01/17 Adds the Latitude and Longitude
>   if (!empty($fields['lat'])) {
>     $form['lat'] = array(
>       '#type' => 'hidden',
>       '#title' => t('Latitudine'),
>       '#default_value' => isset($values['lat']) ? $values['lat'] : '41.895466',
>       '#size' => 50,
>       '#maxlength' => 255,
>       '#required' => ($fields['lat'] == ADDRESSES_FIELD_REQUIRED),
>       '#weight' => empty($field_weights['lat']['weight']) ? 0 : $field_weights['lat']['weight'],
>     );
>   }
>   
>   if (!empty($fields['lon'])) {
>     $form['lon'] = array(
>       '#type' => 'hidden',
>       '#title' => t('Longitudine'),
>       '#default_value' => isset($values['lon']) ? $values['lon'] : '12.482324',
>       '#size' => 50,
>       '#maxlength' => 255,
>       '#required' => ($fields['lon'] == ADDRESSES_FIELD_REQUIRED),
>       '#weight' => empty($field_weights['lon']['weight']) ? 0 : $field_weights['lon']['weight'],
>     );
>   }
> 
>   # PB:2011/01/17 Adds the Latitude and Longitude END
> 
706c733,795
<   return theme('form_element', $element, '<div class="addresses-form">'. $element['#children'] .'</div>');
---
> 	
> 	# PB:2011/01/17 add google map to the field with a default point for retro-compatibility
> 	if (empty($element['lat']['#value'])) {
> 	        $element['lat']['#value'] = 43.768732;
> 	}
> 	
> 	if (empty($element['lon']['#value'])) {
> 	        $element['lon']['#value'] = 11.256901;
> 	}
> 	
> 	$external_js = 'http://maps.google.com/maps/api/js?sensor=false';
> 	$js =   "document.write(unescape(\"%3Cscript src='". $external_js . "' type='text/javascript'%3E%3C/script%3E\"));";
> 	$js .= "$(document).ready(function() {
> 	                        var myLatlng = new google.maps.LatLng(" . $element['lat']['#value'] . ", " . $element['lon']['#value'] . ");
> 	                        var geocoder = null;
> 	                        var myOptions = {
> 	                                zoom: 10,
> 	                                center: myLatlng,
> 	                                mapTypeId: google.maps.MapTypeId.HYBRID,
> 	                                mapTypeControl: true,
> 	                                mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
> 	                                navigationControl: true,
> 	                                navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}
> 	                                }
> 	                        var map = new google.maps.Map(document.getElementById('".$element['#id']."_map'), myOptions);
> 	                        geocoder = new google.maps.Geocoder();
> 	                        var marker = new google.maps.Marker({
> 	                                position: myLatlng,
> 	                                draggable: true,
> 	                                map: map
> 	                        });
> 	                        var addresses = '';
> 	                        $('.addresses-form :input').not(':input[type=hidden]').change(function(){
> 	                                addresses = '';
> 	                                $('.addresses-form :input').not(':input[type=hidden]').each(function(i){
> 	                                        addresses = addresses + ' ' + $(this).val();
> 	                                });
> 	                                if (geocoder) {
> 	                                        geocoder.geocode( { 'address': addresses}, function(results, status) {
> 	                                                if (status == google.maps.GeocoderStatus.OK) {
> 	                                                        map.setCenter(results[0].geometry.location);
> 	                                                        marker.setPosition(results[0].geometry.location);
> 	                                                        $('#" . $element['lat']['#id'] . "').val(results[0].geometry.location.lat());
> 	                                                        $('#" . $element['lon']['#id'] . "').val(results[0].geometry.location.lng());
> 	                                                }
> 	                                        });
> 	                                }
> 	                        });
> 	                        google.maps.event.addListener(marker, 'dragend', function() {
> 	                                geocoder.geocode({
> 	                                        latLng: marker.getPosition()
> 	                                }, function(responses) {
> 	                                        if (responses && responses.length > 0) {
> 	                                                $('#" . $element['lat']['#id'] . "').val(responses[0].geometry.location.lat());
> 	                                                $('#" . $element['lon']['#id'] . "').val(responses[0].geometry.location.lng());
> 	                                        }
> 	                                });
> 	                        });
> 	                });";
> 	drupal_add_js($js, 'inline');
> 	drupal_add_css(drupal_get_path('module', 'addresses') .'/addresses.css');
> 	return theme('form_element', $element, '<div class="addresses-form">'. $element['#children'] .'</div>') . '<div id="'.$element['#id'].'_map" class="map_canvas"></div>';
> 	# PB:2011/01/17 add google map to the field with a default point for retro-compatibility END
Index: addresses/addresses.css
===================================================================
16a17,22
> 
> .map_canvas ,
> #map_canvas {
>        width:100%;
>        height:300px;
> }
\ No newline at end of file
Index: addresses/addresses.inc
===================================================================
653a654,656
>   # PB:2011/01/17 add google map to the field and avoid address format recursion
>   static $address_format;
>   
660a664
>   if (empty($address_format)) {
705d708
<   $address_format = implode("\n", $address_format);
706a710,744
> 	  if(is_array($address_format)===TRUE && empty($address_format)===FALSE){
> 	  	$address_format = implode("<br/>", $address_format);
> 	  }
>   }
> 
>   if (isset($afields['view'])) {
>        drupal_add_css(drupal_get_path('module', 'addresses') .'/addresses.css');
>        $external_js = 'http://maps.google.com/maps/api/js?sensor=false';
>        $js =   "document.write(unescape(\"%3Cscript src='". $external_js . "' type='text/javascript'%3E%3C/script%3E\"));
>                        $(document).ready(function() {
> 
>                                if($('#map_canvas').length != 0) {
>                                        var myLatlng = new google.maps.LatLng(" . $afields['lat'] . ", " . $afields['lon'] . ");
>                                        var myOptions = {
>                                                zoom: 15,
>                                                center: myLatlng,
>                                                mapTypeId: google.maps.MapTypeId.HYBRID,
>                                                mapTypeControl: true,
>                                                mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
>                                                navigationControl: true,
>                                                navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL}
>                                                }
>                                        var map = new google.maps.Map(document.getElementById('map_canvas'), myOptions);
>                                        var marker = new google.maps.Marker({
>                                                position: myLatlng,
>                                                map: map
>                                        });
>                                }
> 
>                                var infowindow = new google.maps.InfoWindow({
>                                    content: '<div class=\"vcard\"><dl class=\"adr\">". $address_format ."</dl></div>'
>                                });
>                                infowindow.open(map,marker);
> 
>                        });";
708c746
<   return '<div class="vcard"><dl class="adr">'. $address_format .'</dl></div>';
---
>        drupal_add_js($js, 'inline');
710a749,752
>   return '<div id="map_canvas"></div><div class="vcard"><dl class="adr">'. $address_format .'</dl></div>';
>   # PB:2011/01/17 add google map to the field and avoid address format recursion END
> }
>   
