全球位置输入自动完成
我正在寻找一个插件来创建一个智能位置表单字段,该字段具有建议的自动完成功能。我无法找到任何合适的东西(谷歌地理编码本身太不可靠,而且它不是为此而设计的),所以我建立了自己的。我觉得 2011 年像这样的开源全局位置输入插件还不存在,这太疯狂了,所以开始尝试一下。
演示位于http://labs.unxposed.net/unxposed/geocode/ 和适用于 Chrome 和 Firefox 4。下载地址为 https://github.com/unxposed/geocode
我遇到了一个主要问题。有时像这样效果很好。在输入中输入 Ban 后,我会收到一个建议列表。输入会自动填充第一个与 Ban 匹配的建议以及选择 Ban 后的输入文本(很像 Chrome 地址栏)。
但是,大多数时候,输入中自动填充选定的文本变得不突出显示,然后光标移动到输入结束(这真的很烦人)。就像这样 - 在我输入 Banbur 之后。
我很确定这与 Google 地图有关,就好像我删除了辅助来源(Google 地理编码)一样问题已解决,自动填充/输入选择始终工作得很好,但为什么会发生这种情况,我该如何解决它?
任何其他改进/优化/建议也将不胜感激!
谢谢
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您的位置数据源是什么?如果是 geonames.org,它们在不同的服务器上有不同的地理位置 - 具有不同的性能特征。因此,在全球范围内的搜索中,由于不同的服务器在不同的时间返回,因此经常会看到混蛋、奇怪的响应等。我发现用户选择一个国家/地区并将其输入城市查询几乎可以消除抖动、奇怪的响应等。如果您使用 geonames.org,它们需要在搜索框中进行归因。如果您使用谷歌名称数据源,我无法发表评论,但您可以检查他们如何处理主要国家和次要国家。另外,请考虑所提供的详细程度。 Geonames 在这方面非常出色。
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.
有一个小部件可以做到这一点,即 jquery ui 自动完成。
http://jqueryui.com/demos/autocomplete/#remote-jsonp
这个演示正是您所需要的,在世界各地选择地点
希望这会有所帮助。干杯
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
如果问题与突出显示有关,您可能需要检查 ajax 调用的成功部分,并确保在正确的时刻取消突出显示。由于该部分总是在变化,因此考虑到带回大量信息并动态更改的性质,它可能会在某一时刻出现故障,
希望这会有所帮助!
附: autocomplete jQuery 将自动完成它提供的任何内容
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
看看这个
下载http://code.google.com/p/geo-autocomplete/
演示:http://geo-autocomplete.googlecode.com/svn /trunk/demo/ui.demo.html
Check out this one
Download http://code.google.com/p/geo-autocomplete/
Demo : http://geo-autocomplete.googlecode.com/svn/trunk/demo/ui.demo.html
OSClass.org 免费提供其主题,该主题具有位置自动完成功能,所有区域都会自动填充。您可以查看他们的演示并从其主题文件中下载代码。
演示(登录并转到“设置”->“位置”部分): http ://demo.osclass.org/general/oc-admin/index.php?page=login
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