<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>坐标获取</title> <script type="text/javascript" src="jquery-1.11.1.min.js"></script> <script charset="utf-8" src="http://map.qq.com/api/js?v=2.exp"></script> </head> <body onload="init()"> <input type="text" name="location" id="sp_location" value="请输入具体地址" class="mid_text" /> <input type="button" class="mid_butt" id="sp_butt" value="获取坐标" /> <br> <label for="latlng"></label> <input type="hidden" name="latlng" value="" class="mid_tet" readonly /> <script type="text/javascript"> $("#sp_butt").click(function(){ var sp3=document.getElementById("sp_location").value; if(sp3==""){ alert("请输入地理位置!"); }else{ if($('label[for=latlng]').html() == '' && typeof(marker) == 'undefined') geocoder.getLocation($('input[name=location]').val()); }; }); // QQ map. var init = function() { var callbacks={ //若服务请求成功,则运行以下函数,并将结果传入 complete:function(result){ var latlng = result.detail.location; if ( $("input[name='latlng']").val() == '' ){ $("input[name='latlng']").val(latlng); $("label[for='latlng']").html($("input[name='latlng']").val()); } }, //若服务请求失败,则运行以下函数 error:function(){ alert("出错了。请先填写地址!"); } } //创建类实例 geocoder = new qq.maps.Geocoder(callbacks); } </script> </body> </html>
转载请注明: haoshu发表于浩叔逛逛>>https://www.haoshu888.com/php/816.html