本文介绍了根据距离和程度获取经度纬度组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我试图获得覆盖某个区域(我的城市)的网格的地理组合。网格是500米* 500米。所以我想输入开始长/纬度组合,距离(500米),度(90或270),并获得下一个长/纬度组合。 我对数学公式一无所知,很难找到解决办法。我发现一些PHP函数可以在两个长/纬度组合之间返回距离。 http:// www。 zipcodeworld.com/samples/distance.php.html http://www.phpro.org/tutorials/Geo-Targetting-With-PHP-And-MySQL.html#3 但是我仍然无法根据自己的需要重建这个东西(我真的很讨厌,sin,tan )。真的很感谢,如果有人帮助我这一点。解决方案这里是找到四个极端点中心点 < script type =text / javascript> 函数toRad(值){返回值* Math.PI / 180; } 函数toDeg(value){返回值* 180 / Math.PI; } 函数computePoint(){ var radius = 6371; // in kms var lat1 = checkField(document.getElementById(lat)); var lon1 = checkField(document.getElementById(long)); var dist = document.getElementById(distance).value; dist = typeof(dist)=='number'? dist:typeof(dist)=='string'&& dist.trim()!=''? + dist:NaN; //警报(Dist+ dist +kms); var angularDist = dist / radius; lat1 = toRad(lat1); lon1 = toRad(lon1); var lat2,lon2,angle = 0; (i = 1; i var brng = toRad(angle); 。 lat2 = lon2 = 0; //第二个纬度 lat2 = Math.asin(Math.sin(lat1)* Math.cos(angularDist)+ Math.cos(lat1)* Math.sin(angularDist)* Math.cos(方位角)); //第二经度 lon2 = lon1 + Math.atan2(Math.sin(brng)* Math.sin(angularDist)* Math.cos(lat1),Math .cos(angularDist) - Math.sin(lat1)* Math.sin(lat2)); if(isNaN(lat2)|| isNaN(lon2))alert(Something is null); // lon2 =(lon2 + 3 * Math.PI)%(2 * Math.PI) - Math.PI; //标准化为-180 .. +180º lat2 = toDeg(lat2); lon2 = toDeg(lon2); // alert(latitude:+ lat2 +,Longitude+ lon2); document.getElementById(lat+ i).innerHTML = lat2; document.getElementById(long+ i).innerHTML = lon2; document.getElementById(ang+ i).innerHTML = angle; $ b函数checkField(field){ var str = field.name var latlon1 latlon = field.value;如果(str.substring(0,3)==lat){ if(latlon> 90.){ alert(Latitudes不能超过90度) field.focus()//不起作用! field.select()} } if(str.substring(0,3)==long){ if(latlon> 180 ){ alert(经度不能超过180度) field.focus() field.select()} } return latlon } 函数parselatlon(instr){ //解析字符串dd.dd dd:mm.mm dd:mm:ss.ss var deg, min,sec,colonIndex,degstr,minstr,str str = instr colonIndex = str.indexOf(:) if(colonIndex == - 1){// dd.dd ? if(!isPosNumber(str)){ badLLFormat(instr) return 0. } else { return parseFloat(str)} $ b $函数isPosNumber(instr){//整数或浮点数 str =+ instr //强制为字符串类型 oneDecimal = false (for i = 0; i< str.length; i ++){ var oneChar = str.charAt(i) if(oneChar ==。&&!oneDecimal){ oneDecimal = true continue } if(oneChar<0|| oneChar>9){ return false } } 返回true } 函数badLLFormat(str){警告(str +是一种无效的纬度/经度格式\ n+ 使用DD.DD DD:MM.MM或DD:MM:SS.SS)} 和HTML看起来像.... <身体GT; < div>输入详情< / div> Latitude:< input type =textid =latname =latvalue =/> <峰; br /> 经度:< input type =textid =longname =longvalue =/> <峰; br /> 距离:< input type =textid =distancename =distancevalue =placeholder =以千米为单位输入距离。 <峰; br /> < input type =submitvalue =Find Pointsname =findPtsonclick =computePoint();/> < div>< h3>< span> < strong>结果将显示在此处< / strong>< / span>< / h3>< / div> < table border =1style =text-align:center> < tr> < th>纬度< / th> 经度< th> th角度(以度为单位)< / th> < / tr> < tr> < td>< label id =lat1value =>< / label> < / TD> < td>< label id =long1value =>< / label> < / TD> < td>< label id =ang1value =>< / label> < / TD> < / tr> < tr> < td>< label id =lat2value =>< / label> < / TD> < td>< label id =long2value =>< / label> < / TD> < td>< label id =ang2value =>< / label> < / TD> < / tr> < tr> < td>< label id =lat3value =>< / label> < / TD> < td>< label id =long3value =>< / label> < / TD> < td>< label id =ang3value =>< / label> < / TD> < / tr> < tr> < td>< label id =lat4value =>< / label> < / TD> < td>< label id =long4value =>< / label> < / TD> < td>< label id =ang4value =>< / label> < / TD> < / tr> < / table> < / body> 我在这里通过GPL捐赠我的代码.... enjoy !! I am trying to get geo combinations of a grid which is covered a certain area (My city). The grid is 500m * 500m. So I wanna enter starting long/latitude combination,distance (500m), degree (90 or 270) and get the next long/latitude combination.I am so unaware of mathematical formulas, and hard to find a solution. I had found some php functions that return distance in between two long/latitude combinations.http://www.zipcodeworld.com/samples/distance.php.htmlhttp://www.phpro.org/tutorials/Geo-Targetting-With-PHP-And-MySQL.html#3But still I cannot rebuild this thing according to my need (I really hate cos,sin,tan). Really appreciate if someone help me over this. 解决方案 Here is the code for finding four extreme points (lat, long) around a center point <script type="text/javascript"> function toRad (value) { return value * Math.PI / 180; } function toDeg (value) { return value * 180 / Math.PI; } function computePoint(){ var radius = 6371; //in kms var lat1 = checkField(document.getElementById("lat")); var lon1 = checkField(document.getElementById("long")); var dist = document.getElementById("distance").value; dist = typeof(dist)=='number' ? dist : typeof(dist)=='string' && dist.trim()!='' ? +dist : NaN; // alert("Dist "+ dist+" kms"); var angularDist = dist / radius; lat1= toRad(lat1); lon1=toRad(lon1); var lat2,lon2, angle = 0; for(i=1; i<5; i++,angle+=90){ var brng = toRad(angle); lat2=lon2=0; // second latitude lat2 = Math.asin(Math.sin(lat1) * Math.cos(angularDist) + Math.cos(lat1) * Math.sin(angularDist) * Math.cos(brng)); // second longitude lon2 = lon1 + Math.atan2(Math.sin(brng) * Math.sin(angularDist) * Math.cos(lat1), Math.cos(angularDist) - Math.sin(lat1) * Math.sin(lat2)); if (isNaN(lat2) || isNaN(lon2)) alert("Something is null"); // lon2 = (lon2+3*Math.PI) % (2*Math.PI) - Math.PI; // normalise to -180..+180º lat2 = toDeg(lat2); lon2 = toDeg(lon2);// alert("latitude: "+lat2 +",Longitude "+lon2); document.getElementById("lat"+i).innerHTML=lat2; document.getElementById("long"+i).innerHTML=lon2; document.getElementById("ang"+i).innerHTML=angle; } } function checkField(field){ var str=field.name var latlon1 latlon=field.value;//parselatlon(field.value) if (str.substring(0,3)=="lat") { if (latlon > 90.) { alert ("Latitudes cannot exceed 90 degrees") field.focus() // Doesn't work! field.select() } } if (str.substring(0,3)=="long") { if (latlon > 180.) { alert ("Longitudes cannot exceed 180 degrees") field.focus() field.select() } } return latlon } function parselatlon(instr){ // Parse strings dd.dd dd:mm.mm dd:mm:ss.ss var deg,min,sec,colonIndex,degstr,minstr,str str=instr colonIndex=str.indexOf(":") if (colonIndex==-1){ // dd.dd? if (!isPosNumber(str)){ badLLFormat(instr) return 0. } else { return parseFloat(str) } } } function isPosNumber(instr){ //integer or float str=""+instr // force to string type oneDecimal=false for (var i=0;i<str.length;i++) { var oneChar=str.charAt(i) if (oneChar=="." && !oneDecimal){ oneDecimal=true continue } if (oneChar < "0" || oneChar > "9") { return false } } return true } function badLLFormat(str){ alert(str+ " is an invalid lat/lon format\n"+ "Use DD.DD DD:MM.MM or DD:MM:SS.SS") } </script>and HTML looks like ....<body> <div>Enter the details </div> Latitude : <input type="text" id="lat" name="lat" value="" /> <br/> Longitude : <input type="text" id="long" name="long" value="" /> <br/> <!-- Bearing : <input type="text" id="bearing" name="bearing" value="" placeholder="Enter angle in degrees" /> <br/>--> Distance : <input type="text" id="distance" name="distance" value="" placeholder ="Enter distance in Kms. " /> <br/> <input type="submit" value="Find Points" name="findPts" onclick="computePoint();"/> <div><h3><span> <strong>Results Will be displayed here</strong></span></h3></div> <table border="1" style="text-align: center"> <tr> <th>Latitude</th> <th>Longitude</th> <th>Angle (in degrees) </th> </tr> <tr> <td><label id="lat1" value=""></label> </td> <td><label id="long1" value=""></label> </td> <td><label id="ang1" value=""></label> </td> </tr> <tr> <td><label id="lat2" value=""></label> </td> <td><label id="long2" value=""></label> </td> <td><label id="ang2" value=""></label> </td> </tr> <tr> <td><label id="lat3" value=""></label> </td> <td><label id="long3" value=""></label> </td> <td><label id="ang3" value=""></label> </td> </tr> <tr> <td><label id="lat4" value=""></label> </td> <td><label id="long4" value=""></label> </td> <td><label id="ang4" value=""></label> </td> </tr> </table> </body>I here by donate my code under GPL.... enjoy!! 这篇关于根据距离和程度获取经度纬度组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-11 16:35