問題描述
我正在使用 Grails 下的 Google 地圖進(jìn)行混搭,用戶可以通過選擇創(chuàng)建 geofences地圖上的一個點(diǎn)和一個半徑.這會存儲在我的數(shù)據(jù)庫中,并且應(yīng)用程序會不斷從 GPS 設(shè)備接收一組坐標(biāo).
I am doing a mashup using Google Maps under Grails where users can create geofences by selecting a point on the map and a radius. This get stored on my database and the application receives constantly a set of coordinates from a GPS device.
我想將接收到的坐標(biāo)與圓圈中存儲的區(qū)域進(jìn)行比較.如果該點(diǎn)在圓圈內(nèi)(或外),程序?qū)⒂|發(fā)一個動作.但是,我想知道如何確定坐標(biāo)是否位于圓的內(nèi)部/外部.有一個 Javascript 庫可以執(zhí)行此操作,但我需要在服務(wù)器上執(zhí)行此操作.
I would like to compare the received coordinates with the area stored in the circles. If the point is inside (or outside) the circle the program will fire an action. However, I would like to know how I can find out if the coordinates are located inside/outside the circle. There is a Javascript library which allows doing this but I need to do this on the server.
是否有用于此的 Java(甚至 Groovy)庫?你將如何實(shí)現(xiàn)它?
Is there a Java (or even Groovy) library for this? How would you implement it?
推薦答案
如果點(diǎn)到圓心的距離是<= 圓的半徑 那么它在圓圈內(nèi).
如果該區(qū)域由多個圓圈組成,而不是與所有圓圈相比......它不會花費(fèi)那么長時間.
if distance from point to center of circle is <= radius of circle then it is inside the circle.
if the area is made of more than one circle than compare to all the circles... it won't take that long.
java.awt.geom.Point2D.Double 非常適合.
java.awt.geom.Point2D.Double is perfect for this.
這篇關(guān)于在圓中尋找坐標(biāo)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!