第一次做google map 开发,对很多东西不熟习,除了看api外,就是各种尝试。也谢谢帮我的 睥睨?在下班前,把这些整理了下传上来,方便自己以后用到,同时也给做map开发的新人一点提示吧
- function?searchmap(){??
- ???//先从输入框中取出要搜的地名??
- ???var?address=$("#check_box").val();??
- ???if("?"==address){??
- ????????alert("请输入要定位的地名!");??
- ????????return?false;??
- ???}else{??
- ????geocoder?=?new?google.maps.Geocoder();?//注意:还有一个全局的?var?geocoder?对象??
- ????if(geocoder){??
- ????????geocoder.geocode({'address':?address?},?function(results,?status)?{??
- ????????????if?(status?==?google.maps.GeocoderStatus.OK)?{??
- ????????????????var?GeoCode?=?((results[0].geometry.location).toString().replace(/[()]/g,?'')).split(",",2);??
- ????????????????var?lat?=?parseFloat(GeoCode[0]);//纬度??
- ????????????????var?lng?=?parseFloat(GeoCode[1]);//经度??
- ????????????????var?mylatlng?=?new?google.maps.LatLng(lat,?lng);??????
- ????????????????map.setCenter(mylatlng);???????????????????????????????????????????
- ????????????????//对搜索到的这个点进行标注??
- ????????????????????????????var?marker?=?new?google.maps.Marker({??
- ????????????????????map:?map,??
- ????????????????????position:?mylatlng,??
- ????????????????????title:address??
- ????????????????});??
- ????????????//点击事件,下面的经度和纬度是我要使用的,点击的时候弹出层??
- ????????????????????????????????google.maps.event.addListener(marker,?'click',?function(){??
- ??????????????????????showLayer('add_button');??
- ??????????????????????$("#weidu_id").val(lat);??
- ??????????????????????$("#jingdu_id").val(lng);??
- ????????????????????});??
- ??????????????????????
- ????????????????}?else?{??
- ????????????????alert("谷歌地图没有找到的原因是:"?+?status);??
- ????????????????}??
- ????????????});??
- ????????}??
- ???}??
- } ? ? ?