sgruhier / jquery-addresspicker

JQuery UI widget : address autocomplete field by google maps V3 geocoding service
xilinus.com/jquery-addresspicker/demos/index.html
592 stars 221 forks source link

Save zoom and integrate with Ruby on Rails #24

Closed luca3m closed 10 years ago

luca3m commented 11 years ago

Hi,

I've added the option to save the zoom of the map, it's useful for saving it and later redisplay the map with the same condition. Also I added "//= require" directives so the script works nice with Rails Assets Pipeline.

I hope it will be useful and thanks for your work :)

Regards

mrcmorales commented 10 years ago

ping.

I need this functionally.

Thanks

sgruhier commented 10 years ago

You don't need this, you can do it with current code. You can set map zoom on addresspicker options like this:

    var addresspickerMap = $( "#addresspicker_map" ).addresspicker({
      mapOptions: {
        zoom: 4,
        center: new google.maps.LatLng(46, 2),
        scrollwheel: false,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
    });

And you can listen for any map changes like this:

    // Update zoom field
    var map = $("#addresspicker_map").addresspicker("map");
    google.maps.event.addListener(map, 'idle', function(){
      $('#zoom').val(map.getZoom());
    });

I just updated the demo with this code.

Regarding the rails comment, it's out of the scope of the plugin and you cannot force people to use jquery like this instead of using a CDN for example.

mrcmorales commented 10 years ago

Thanks,

But then not is zoom updated when click to zoom buttons.

If is done like do @luca3m , then you can do it:

      var gmap = addresspickerMap.addresspicker( "map");
        google.maps.event.addListener(gmap, 'zoom_changed', function() {
            addresspickerMap.addresspicker("updatePosition");
        });

And every time that change zoom, zoom value is updated.

sgruhier commented 10 years ago

Sorry, I don't understand what you say

mrcmorales commented 10 years ago

Sorry,

Your solution only update zoom after search location in autocomplete, not every time that zoom is changed using zoom button in map.

sgruhier commented 10 years ago

Yes it does I updated the online demo http://xilinus.com/jquery-addresspicker/demos/index.html with the latest commit. Zoom is displayed below Lat/Lng

mrcmorales commented 10 years ago

Ok, now works.

Thanks.