web根据地址定位
来源:互联网 发布:2017大数据就业前景 编辑:程序博客网 时间:2024/05/22 11:36
直接上代码:
<!DOCTYPE>
<
html
>
<
head
>
<
meta
name
=
"viewport"
content
=
"initial-scale=1.0, user-scalable=no"
/>
<
meta
http-equiv
=
"Content-Type"
content
=
"text/html; charset=gbk"
/>
<
title
>百度地图</
title
>
<
style
type
=
"text/css"
>
html{height:100%}
body{height:100%;margin:0px;padding:0px}
#container{height:100%}
</
style
>
<
script
src
=
"http://api.map.baidu.com/api?v=1.4"
type
=
"text/javascript"
></
script
>
</
head
>
<
body
>
<
input
type
=
"text"
id
=
"cityName"
value
=
"福州"
/>
<
input
type
=
"button"
onclick
=
"setCity()"
value
=
"查找"
/>
<
div
id
=
"container"
style
=
"width:1024px;height:600px;"
></
div
>
<
script
type
=
"text/javascript"
>
var map = new BMap.Map("container"); //在container容器中创建一个地图,参数container为div的id属性;
var point = new BMap.Point(120.2,30.25); //创建点坐标
map.centerAndZoom(point, 14); //初始化地图,设置中心点坐标和地图级别
map.enableScrollWheelZoom(); //激活滚轮调整大小功能
map.addControl(new BMap.NavigationControl()); //添加控件:缩放地图的控件,默认在左上角;
map.addControl(new BMap.MapTypeControl()); //添加控件:地图类型控件,默认在右上方;
map.addControl(new BMap.ScaleControl()); //添加控件:地图显示比例的控件,默认在左下方;
map.addControl(new BMap.OverviewMapControl()); //添加控件:地图的缩略图的控件,默认在右下方; TrafficControl
var search = new BMap.LocalSearch("中国", {
onSearchComplete: function(result){
if (search.getStatus() == BMAP_STATUS_SUCCESS){
var res = result.getPoi(0);
var point = res.point;
map.centerAndZoom(point, 11);
}
},renderOptions: { //结果呈现设置,
map: map,
autoViewport: true,
selectFirstResult: true
} ,onInfoHtmlSet:function(poi,html){//标注气泡内容创建后的回调函数,有了这个,可以简单的改一下返回的html内容了。
// alert(html.innerHTML)
}//这一段可以不要,只不过是为学习更深层次应用而加入的。
});
function setCity(){
search.search(document.getElementById("cityName").value);
}
search.search(document.getElementById("cityName").value);
</
script
>
</
body
>
</
html
>
第二种: 谷歌
首先引入 <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
代码如下
js代码
var myLatlng = new google.maps.LatLng(ret.attache.json.lat, ret.attache.json.lng);// 中国地图全图
var optMap =
{
zoom: 15,
center: myLatlng,
streetViewControl:false,
mapTypeControl: true,
mapTypeControlOptions: {
mapTypeIds: [/**google.maps.MapTypeId.SATELLITE ,google.maps.MapTypeId.HYBRID* */], // comment
position: google.maps.ControlPosition.TOP_LEFT
},
// navigationControl: true,
navigationControlOptions: {
style: google.maps.NavigationControlStyle.DEFAULT,
position: google.maps.ControlPosition.LEFT
},
//ROADMAP SATELLITE
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('container'),optMap);
map.setOptions({Zoom:18,center:myLatlng});
html
<div id="locationDiv" >
<div id="container" style="position:relative; width:450px; height:300px;"></div>
</div>
- web根据地址定位
- 根据IP地址定位城市
- 根据IP地址对访问者定位
- linux_kernel_debug_tips_根据函数地址定位函数名称
- java根据IP地址获取本地定位
- 使用MaxMind 根据IP地址对访问者定位
- 根据设备定位所得的经纬度,获得具体的地址
- Android使用Google Map服务-根据地址定位
- Android使用Google Map服务-根据地址定位
- 百度地图接口,根据IP地址定位当前城市
- java web根据访问的ip地址获取MAC地址
- net/json正则表达式应用 微信定位后根据腾讯地图获取定位地址
- iOS 根据 crash 崩溃 报告的内存地址定位到代码位置
- iOS 根据 crash 崩溃 报告的内存地址定位到代码位置
- iOS 根据 crash 崩溃 报告的内存地址定位到代码位置
- iOS 根据 crash 崩溃 报告的内存地址定位到代码位置
- 根据IP定位所在城市(HTML,js,新浪IP地址库)
- iOS 根据 crash 崩溃 报告的内存地址定位到代码位置
- linux的nohup命令的用法
- 计算机网络复习——传输层
- 修改hive表location
- Git Patch使用: 生成,导入,解决冲突
- java中常用的设计模式-装饰设计模式
- web根据地址定位
- jQuery的碎碎念
- Mysql的存储引擎的类型,MyISAM&InnoDB等
- python程序语言的安装
- Oracle游标(一)
- VS2010 编译错误 RC1106: invalid option -ologo
- iOS - apple官方ARC文档关键点摘录
- python文件
- 数据库基础