$(document).ready(function () { 002. 2 /* 003. 3 根据地址信息获取经纬度,返回json对象: 004. 4 status Int 返回结果状态值,成功返回0。 005. 5 location object 经纬度坐标 006. 6 lat float 纬度值 007. 7 lng float 经度值 008. 8 precise Int 位置的附加信息,是否精确查找。1为精确查找,0为不精确。 009. 9 confidence Int 可信度 010. 10 level string 地址类型 011. 11 012. 12 { 013. 13 status: 0, 014. 14 result: 015. 15 { 016. 16 location: 017. 17 { 018. 18 lng: 116.30814954222, 019. 19 lat: 40.056885091681 020. 20 }, 021. 21 precise: 1, 022. 22 confidence: 80, 023. 23 level: '商务大厦' 024. 24 } 025. 25 } 026. 26 */ 027. 27 $( '#search_address' ).click(function () { 028. 28 var address = $.trim($( '#address' ).val()); 029. 29 if (address != undefined && address != '' ) { 030. 30 var url = 'http://api.map.baidu.com/geocoder/v2/?ak=eIxDStjzbtH0WtU50gqdXYCz&;output=json&address=' + encodeURIComponent(address); 031. 31 //根据地点名称获取经纬度信息 032. 32 $.ajax({ 033. 33 type: 'POST' , 034. 34 url: url, 035. 35 dataType: 'JSONP' , 036. 36 success: function (data) { 037. 37 if (parseInt(data.status) == 0 ) { 038. 38 $( '#lng' ).html( '经度:' + data.result.location.lng); 039. 39 $( '#lat' ).html( '纬度:' + data.result.location.lat); 040. 40 } 041. 41 } 042. 42 }); 043. 43 } 044. 44 }); 045. 45 /* 046. 46 根据经纬度获取详细地址及其周边信息,返回json对象: 047. 47 status constant 返回结果状态值, 成功返回0,其他值请查看附录。 048. 48 location 049. 49 lat 纬度坐标 050. 50 lng 经度坐标 051. 51 formatted_address 结构化地址信息 052. 52 business 所在商圈信息,如 '人民大学,中关村,苏州街' 053. 53 addressComponent city 城市名 054. 54 district 区县名 055. 55 province 省名 056. 56 street 街道名 057. 57 street_number 街道门牌号 058. 58 pois(周边poi数组) 059. 59 addr 地址信息 060. 60 cp 数据来源 061. 61 distance 离坐标点距离 062. 62 name poi名称 063. 63 poiType poi类型,如’ 办公大厦,商务大厦’ 064. 64 point poi坐标{x,y} 065. 65 tel 电话 066. 66 uid poi唯一标识 067. 67 zip 邮编 068. 68 */ 069. 69 $( '#search_lng_lat' ).click(function () { 070. 70 var lng = $.trim($( '#txtlng' ).val()); 071. 71 var lat = $.trim($( '#txtlat' ).val()); 072. 72 var url = 'http://api.map.baidu.com/geocoder/v2/?ak=eIxDStjzbtH0WtU50gqdXYCz&;output=json&pois=1&location=' + lat + ',' + lng; 073. 73 $.ajax({ 074. 74 type: 'POST' , 075. 75 url: url, 076. 76 dataType: 'JSONP' , 077. 77 success: function (data) { 078. 78 if (parseInt(data.status) == 0 ) { 079. 79 var result = '地址:' + data.result.formatted_address + '</br>' ; 080. 80 result += '省名:' + data.result.addressComponent.province + '</br>' ; 081. 81 result += '城市名:' + data.result.addressComponent.city + '</br>' ; 082. 82 result += '区县名:' + data.result.addressComponent.district + '</br>' ; 083. 83 result += '街道名:' + data.result.addressComponent.street + '</br>' ; 084. 84 result += '街道门牌号:' + data.result.addressComponent.street_number + '</br>' ; 085. 85 result += '周边信息:</br>' ; 086. 86 for (var i = 0 ; i < data.result.pois.length; i++) { 087. 87 result += '地址信息:' + data.result.pois[i].addr 088. 88 + ',数据来源:' + data.result.pois[i].cp 089. 89 + ',离坐标点距离:' + data.result.pois[i].distance 090. 90 + ',poi名称:' + data.result.pois[i].name 091. 91 + ',poi类型:' + data.result.pois[i].poiType 092. 92 + ',poi坐标x:' + data.result.pois[i].point.x 093. 93 + ',poi坐标y:' + data.result.pois[i].point.y 094. 94 + ',电话:' + data.result.pois[i].tel 095. 95 + ',poi唯一标识:' + data.result.pois[i].uid 096. 96 + ',邮编:' + data.result.pois[i].zip + '</br>' ; 097. 97 } 098. 98 $( '#spanadde<a href="http://www./design/wrss/" target="_blank" class="keylink">rss</a>' ).html(result); 099. 99 } 100. 100 } 101. 101 }); 102. 102 }); 103. 103 }); |
|
来自: 好好学戏 > 《javascript(jquery)》