问题
I was looking for a plugin to create a smart location form field which has a suggested autocomplete. I was unable to find anything suitable (Google Geocode is too unreliable on its own, and it isn't designed for this) so I built my own. I thought it was crazy that in 2011 an open-source global location input plugin like this didn't exist so set out to give it a go.
The demo is here http://labs.unxposed.net/unxposed/geocode/ and is working on Chrome and Firefox 4. Download is here https://github.com/unxposed/geocode
There is one major issue I am having with it. Sometimes it works great like so. On typing Ban in the input I get a list of suggestions back. The input is autofilled with the first suggestion back matching Ban and the input text after Ban is selected (much like the Chrome address bar).
However, much of the time the autofill selected text in the input becomes unhighlighted and the cursor then moves to the end of the input (which is really annoying). Like so - after I type Banbur.
I am pretty sure this is related to Google Maps as if I remove the secondary source (Google Geocode) the issue is resolved and autofill/input select works great consistently, but why is this happening, and how can I fix it?
Any other improvements/optimisations/suggestions would be greatly appreciated too!
Thanks
回答1:
What is your data source of locations? If it is geonames.org, they have different geographies on different servers - with different performance characteristics. Hence it is common on a worldwide search to see jerks, odd responses, etc. as different servers toss back at different times. I found that user selection of a country, and feeding that into the city query pretty much eliminates jerkiness, odd responses, etc. If you are using geonames.org, they require attribution at the search box. If you are using a google data source of names, I can't comment, but you might check how they handle major versus minor countries. Also, think about the level of detail provided. Geonames is remarkable on that score.
回答2:
There is a widget that does that, the jquery ui autocomplete.
http://jqueryui.com/demos/autocomplete/#remote-jsonp
This demo is exactly what you need, selecting locations over the world
Hope this helps. Cheers
回答3:
If the problem is related to the highlighting you might want to check the success section of your ajax call and make sure that you are un-highlighting in the right moment. Because the section is always changing it might glitch at one point given the nature of bringing back lots of info and altering dynamically
hope this helps!
ps. autocomplete jQuery will autocomplete anything it feeds from
回答4:
Check out this one Download http://code.google.com/p/geo-autocomplete/ Demo : http://geo-autocomplete.googlecode.com/svn/trunk/demo/ui.demo.html
回答5:
OSClass.org provides its theme for free which has location autocomplete with all areas being populated automatically. This you can check in their demo and download the code from within their theme files. Demo (login and go to Settings->location section) : http://demo.osclass.org/general/oc-admin/index.php?page=login
来源:https://stackoverflow.com/questions/5714477/global-location-input-autocomplete