有没有办法使用谷歌地图来自动完成一个用户位置的方法吗? [英] Is there a way to use Google Maps to Autocomplete a users Location?

查看:187
本文介绍了有没有办法使用谷歌地图来自动完成一个用户位置的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个文本框为人们在输入自己的位置。随着人们键入时,他们应该看到的谷歌地图的自动完成建议

There's a Text Box for people to type in their location. As people type, they should see Google Map's Suggest autocomplete.

然后,一旦他们选择从自动完成的东西,我想的警报纬度/长

Then, once they select something from the auto-complete, I would like an alert of the lat/long.

是否可以使用谷歌地图这些2个任务?

Is it possible to use Google Maps for these 2 tasks?

我的目标是获得人的纬度/长,在可能的最简单的方法。
理想的情况下...有一个插件来做到这一点?

My objective is to get the person's Lat/long, in the simplest way possible. Ideally...is there a plugin to do this?

推荐答案

我已经设置了演示这里。该提示功能是由中游离碱 jQuery插件的照顾。

I have set up the demo here. The suggest functionality is taken care of by the Freebase jquery plugin.

<script type="text/javascript" src="./jquery-1.4.2.js"></script> 
<link type="text/css" rel="stylesheet" href="http://freebaselibs.com/static/suggest/1.3/suggest.min.css" />
<script type="text/javascript" src="http://freebaselibs.com/static/suggest/1.3/suggest.min.js"></script>
<script type="text/javascript">
$(function() {
  $("#address").suggest({type:'/location/citytown'});
});
</script>

标记的使用谷歌API V3添加

The marker's are added using google api v3

var marker = new google.maps.Marker({
        position: latlng,
        map: map,
        zIndex: Math.round(latlng.lat()*-100000)<<5
    });

标记的位置将被添加到内容字符串信息窗口

infowindow.setContent("<h3>Markers "+(marker_id+1)+" "+marker.position+"</h3>");

完整的JavaScript可以发现这里

这篇关于有没有办法使用谷歌地图来自动完成一个用户位置的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆