diff --git a/app/views/maps/_google_map.js.erb b/app/views/maps/_google_map.js.erb index c0e2bd1..ccf1262 100644 --- a/app/views/maps/_google_map.js.erb +++ b/app/views/maps/_google_map.js.erb @@ -9,9 +9,9 @@ var previousCenter; function getAddress(latlng) { $('location-fields').addClassName("loading"); - if (latlng != null) { + if (latlng != null) { geocoder.geocode( {'latLng': latlng}, showAddress); - } + } } function codeAddress() { @@ -21,7 +21,7 @@ function codeAddress() { var address = $('profile_data_address').value + "-" + $('profile_data_zip_code').value + "," + $('profile_data_city').value+ "-" + $('profile_data_state').value + "," + country_option; if (geocoder) { - geocoder.geocode( { 'address': address}, function(results, status) { + geocoder.geocode({ 'address': address}, function(results, status) { if (status == google.maps.GeocoderStatus.OK) { map.setCenter(results[0].geometry.location); marker.setPosition(results[0].geometry.location); @@ -78,66 +78,65 @@ function getAddressData() { } function showAddress(results, status) { - if (status == google.maps.GeocoderStatus.OK) { - map.setCenter(results[0].geometry.location); updateFields(results[0]); - + map.setCenter(marker.getPosition()); } else { alert("<%=_("Address not found, reason:")%>" + translate_status(status)); } - } function updateFields(place) { + $('location-fields').removeClassName("loading"); + var position = marker.getPosition(); $('profile_data_lat').value = position.lat(); $('profile_data_lng').value = position.lng(); - $('location-fields').removeClassName("loading"); form = jQuery('#location-form')[0]; form.lat = marker.getPosition().lat(); form.lng = marker.getPosition().lng(); var components_len = place.address_components.size(); + if (components_len < 2) + return; - if(components_len < 2) - { - return false; - } - - var components = place.address_components; var address = ""; var zip_code = ""; var city = ""; var state = ""; var country_code = ""; - var i = 0; - - for( i =0 ; i < components_len; i ++) - { - - if (components[i].types[0] == 'country') - country_code = components[i].short_name; - else if (components[i].types[0] == 'administrative_area_level_1') - state = components[i].long_name; - else if (components[i].types[0] == 'locality') - city = components[i].long_name; - else if (components[i].types[0] == 'sublocality') - address = components[i].long_name + "-" + address; - else if (components[i].types[0] == "route") - address = components[i].long_name + address; - else if (components[i].types[0] == "street_number") - address = address + "," + components[i].short_name ; - else if (components[i].types[0] == 'postal_code') - zip_code = components[i].short_name; + + var i; + for(i=0; i < components_len; i++) { + type = place.address_components[i].types[0]; + value = place.address_components[i]; + if (type == 'country') + country_code = value.short_name; + else if (type == 'administrative_area_level_1') + state = value.long_name; + else if (type == 'locality') + city = value.long_name; + else if (type == 'sublocality') + address = value.long_name + "-" + address; + else if (type == "route") + address = value.long_name + address; + else if (type == "street_number") + address = address + "," + value.short_name; + else if (type == 'postal_code') + zip_code = value.short_name; } - $('profile_data_country').value = country_code; - $('profile_data_state').value = state; - $('profile_data_address').value = address; - $('profile_data_city').value = city; - $('profile_data_zip_code').value = zip_code; + if (country_code) + $('profile_data_country').value = country_code; + if (state) + $('profile_data_state').value = state; + if (address) + $('profile_data_address').value = address; + if (city) + $('profile_data_city').value = city; + if (zip_code) + $('profile_data_zip_code').value = zip_code; } @@ -157,29 +156,25 @@ function initialize_map() { var myOptions = { zoom: 8, center: latlng, - mapTypeId: google.maps.MapTypeId.ROADMAP + mapTypeId: google.maps.MapTypeId.HYBRID } center = latlng; map = new google.maps.Map(document.getElementById("location-map"), myOptions); - continueLoadMapV3() -} - -function continueLoadMapV3() { - - marker = new google.maps.Marker({ - position: center, - map: map, - draggable: true - }); + marker = new google.maps.Marker({ + position: center, + map: map, + draggable: true + }); - google.maps.event.addListener(marker, "dragend", function() { - move = false; - getAddress(marker.getPosition()); - enable_save(); - }); + google.maps.event.addListener(marker, "dragend", function() { + move = false; + getAddress(marker.getPosition()); + map.setCenter(marker.getPosition()); + enable_save(); + }); } @@ -188,7 +183,7 @@ window.onload = initialize_map; var delay_autocomplete = 500; jQuery.noConflict(); -jQuery(document).ready(function (){ +jQuery(document).ready(function () { jQuery.widget( "custom.catcomplete",jQuery.ui.autocomplete, { _renderMenu: function( ul, items ) { @@ -204,7 +199,6 @@ jQuery(document).ready(function (){ } }); - jQuery("#profile_data_city").catcomplete({ source: "../maps/search_city", minLength: 3, @@ -219,21 +213,13 @@ jQuery(document).ready(function (){ }); jQuery("#profile_data_city").keyup(function(){ - disable_save(); - }); - jQuery("#profile_data_state").keyup(function(){ - disable_save(); - }); - jQuery("#profile_data_country").change(function(){ - disable_save(); - }); }); -- libgit2 0.21.2