Location search autocomplete that integrates with bing/google geocoding

强颜欢笑 提交于 2019-11-29 23:22:11

If you don't want to maintain your own database of locations (good for you!), then you might look at Freebase and their Freebase Suggest plugin for jQuery. They'll do all the auto-completion and even the suggestion UI for you and you can specify that you just want to auto-complete locations (or only US counties, or whatever).

There exist gazetteers who can provide the database of location names but won't do the auto-complete UI for you. GeoNames, for example, has a nice set of web services, which you could match up with jQuery Autocomplete.

Tom Lehman

We do something similar for the "billing address" field on https://bombsheets.com/ -- you need to do an AJAX call to get the autocomplete options:

 $(".address-autocomplete").autocomplete('/get_address', {
   delay: 250,
   scrollHeight: 400,
   matchSubset: false,
   cacheLength: 10,
   minChars: 3
 });

And then use a geolocation API server-side to get the actual addresses (we use Rails' excellent GeoKit).

See this question for some additional color.

https://github.com/lorenzsell/Geocoded-Autocomplete This jQuery plugin uses Google Geocoding Javascript API and jQuery UI Autocomplete.

 <script>
        function init() {
            var input = document.getElementById('locationTextField');
            var autocomplete = new google.maps.places.Autocomplete(input);

            ///Start for getting lat and lang

            google.maps.event.addListener(autocomplete, 'place_changed',
               function() {
                  var place = autocomplete.getPlace();
                  var lat = place.geometry.location.lat();
                  var lng = place.geometry.location.lng();
                  document.getElementById("lat").innerHTML = "Lat: "+lat+"<br />Lng: "+lng;
               }
            );

            ////End
        }

        google.maps.event.addDomListener(window, 'load', init);
    </script>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!