google api autocomplete
<input class="flex-item" id="autocomplete" placeholder="address, zip or city" onFocus="geolocate()" type="text"></input>
var autocomplete;
function geolocate() {
if(!autocomplete){
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')),{ types: ['geocode'] });
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = new google.maps.LatLng(
position.coords.latitude, position.coords.longitude);
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
<body onload="initialize()">
<form class="form-address" id="address">
<!-- Search Field -->
<div class="flex-container c-1column" id="locationField">
<label>Search for your address</label>
<input class="flex-item" id="autocomplete" placeholder="address, zip or city" onFocus="geolocate()" type="text"></input>
</div>
<!-- Street Address -->
<div class="flex-container">
<label>Street address</label>
<div class="flex-item c-2column"><input id="streetNo" ></input></div>
<div class="flex-item c-2column"><input id="route" ></input></div>
</div>
<!-- City -->
<div class="flex-container">
<label>City</label>
<input class="flex-item c-1column" id="city" ></input>
</div>
<!-- State & Zip -->
<div class="flex-container">
<div class="flex-item c-2column">
<label>State</label>
<input id="state" ></input>
</div>
<div class="flex-item c-2column">
<label>Zip code</label>
<input id="zipcode" ></input>
</div>
</div>
<!-- Country -->
<div class="flex-container">
<label>Country</label>
<input class="flex-item c-1column" id="country" ></input>
</div>
</form>
</body>
var placeSearch, autocomplete;
var componentForm = {
street_number: 'short_name',
route: 'long_name',
locality: 'long_name',
administrative_area_level_1: 'short_name',
country: 'long_name',
postal_code: 'short_name'
};
var myForm = {
street_number: 'streetNo',
route: 'route',
locality: 'city',
administrative_area_level_1: 'state',
country: 'country',
postal_code: 'zipcode'
};
function initialize() {
autocomplete = new google.maps.places.Autocomplete(
(document.getElementById('autocomplete')),{ types: ['geocode'] });
google.maps.event.addListener(autocomplete, 'place_changed', function() {
fillInAddress();
});
}
// [START region_fillform]
function fillInAddress() {
var place = autocomplete.getPlace();
/* for (var component in componentForm) {
document.getElementById(component).value = '';
document.getElementById(component).disabled = false;
} */
// Get each component of the address from the place details
// and fill the corresponding field on the form.
for (var i = 0; i < place.address_components.length; i++) {
var addressType = place.address_components[i].types[0];
if (componentForm[addressType]) {
var val = place.address_components[i][componentForm[addressType]];
// alert(myForm[addressType])
document.getElementById(myForm[addressType]).value = val;
}
}
}
function geolocate() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
var geolocation = new google.maps.LatLng(
position.coords.latitude, position.coords.longitude);
var circle = new google.maps.Circle({
center: geolocation,
radius: position.coords.accuracy
});
autocomplete.setBounds(circle.getBounds());
});
}
}
google api autocomplete的更多相关文章
- 借用Google API在线生成网站二维码地址方法
二维码其实很早就出现了,在国外很多年前就已经在应用了,国内这两年才开始异常的火爆,智能手机的发展,以及微博.微信等移动应用带动了二维码的普及.那么,如果为网址在线生成二维码呢?下面我们就来介绍一下Go ...
- [Java] - Google API调用
由于Google已经完成被墙,要上Google必需使用代理或VPN. 这里使用的是Google的GoAgent代理做开发.(如何使用GoAgent,这里不写了,忽略500字.....) 本地测试的Go ...
- PHP二维码生成的方法(google APi,PHP类库,libqrencode等)
原文地址: http://blog.csdn.net/liuxinmingcode/article/details/7910975 ================================== ...
- Google API在线生成二维码的方法
1.先看一个实例,是用Google API生成西部e网的网站地址www.weste.net二维码的方法: http://chart.apis.google.com/chart?cht=qr&c ...
- 缺少google api密钥,因此chromium的部分功能将无法使用”的解决办法
使用Chromium时会遇到 "缺少google api密钥,因此chromium的部分功能将无法使用"提示,google了一下 setx Google_API_K ...
- 利用google api生成二维码名片例子
二维条码/二维码可以分为堆叠式/行排式二维条码和矩阵式二维条码.堆叠式/行排式二维条码形态上是由多行短截的一维条码堆叠而成:矩阵式二维条码以矩阵的形式组成,在矩阵相应元素位置上用“点”表示二进制“1” ...
- google API的.NET库
Goolge发布了一个新的google API .NET库,是一个Portable Class Library,所以无论是.NET,WinTRy,Windows Phone或者Silverlight都 ...
- Google API v3 设置Icon问题处理
1.查看API实现 //虽然比较符合API实现的思想但这个没法; //会产生Uncaught TypeError: undefined is not a function //google API n ...
- ecshop使用Google API及OAuth2.0登录授权(PHP)
一.申请clientID https://console.developers.google.com/project 二.开启Google+ API权限 https://console.develop ...
随机推荐
- maven多模块下使用JUnit进行单元测试
1.选中需要进行测试的service类,右键->new->other->JUnit Test Case,如下图: 2.编写测试代码如下: AppServiceTest.java im ...
- 漂亮的Linux命令提示符
漂亮的Linux命令提示符 每天面对着白底黑字(黑底白字)的命令行是否枯燥泛味呢?生活应给是五彩缤纷的,何不为单调无味的生活增添一抹色彩? 下面一起体验一下Linux命令行提示符惊险的整容之旅 惊鸿一 ...
- ListView下拉加载一(分页)
首先创建在主xml里放置一个listview列表,代码如下: <LinearLayout xmlns:android="http://schemas.android.com/apk/r ...
- white-space: nowrap 与字符串(文本)换行
在需要对字符串进行元素内换行时,我们通常要对该元素设置相关属性约束以及宽度. 例如:style="word-wrap:break-word; word-break: break-all; w ...
- reggetvalue在xp下加载失败
在windows 32bit的xp下使用reggetvalue会提示,无法定位程序输入点reggetvalueW于动态链接库advapi32.dll(UNICODE).reggetvalueA也是无法 ...
- weex 小结 --官方扩展组件
<wxc-tabbar> 页面底部的 tab 标签,通过点击在不同页面之间切换 属性: selected-index {number}:设置默认选中的 tab 索引,默认值为 0(第一个 ...
- 无法删除对象 '产品',因为该对象正由一个 FOREIGN KEY 约束引用。
在删除northwindcs表时,发生报错,消息 3726,级别 16,状态 1,第 2 行,无法删除对象 '产品',因为该对象正由一个 FOREIGN KEY 约束引用.此时判断是因为有其他表的外键 ...
- BWT压缩算法(Burrows-Wheeler Transform)
参考: BWT (Burrows–Wheeler_transform)数据转换算法 压缩技术主要的工作方式就是找到重复的模式,进行紧密的编码. BWT(Burrows–Wheeler_transfor ...
- samba完美安装
感觉是一个相当强大的东西. Samba是在Linux和UNIX系统上实现SMB协议的一个免费软件.它为局域网内的不同计算机之间提供文件及打印机等资源的共享服务.为客户机/服务器型协议,客户机通过该协议 ...
- iOS scrollview循环播放加缩放
前些日子一直在研究3d的框架没有时间写博客,不过最后需求改了,也没研究出个啥.这段时间出了新的需求,需要循环播放图片,并且滑动的时候中间的图片有缩放的效果.刚开始想在网上搜索,不过并没有找到合适的de ...