為了考賞自己所以買了新背包,超開心。
然後該工作的還是要工作,最近實做了一個試著判斷封閉區域內外的程式,詳細說明如下:
本來還有更高畫質的圖檔的,可惡Google竟然不給我傳。
然後傳完赫然發現第三個點點位置跑掉了!(大驚)
/**
* 這是主要的演算法。
*
* @param p
* p點,待測點。
* @param polygon
* 依序點集合所產生的封閉區間。
* @param mStringBuffer
* 將演算法的資訊顯示出來所需要的文字容器
* @return true is inside;false is outside
*/
private boolean InsidePolygon(Vector<GeoPoint> polygon, GeoPoint p,
StringBuffer mStringBuffer) {
// ref: http://paulbourke.net/geometry/insidepoly/
int counter = 0;
int i;
double xinters;
GeoPoint p1, p2;
p1 = polygon.get(0);
for (i = 1; i <= polygon.size(); i++) {
p2 = polygon.get(i % polygon.size());
if (p.getLatitudeE6() > Math.min(p1.getLatitudeE6(),
p2.getLatitudeE6())) {
if (p.getLatitudeE6() <= Math.max(p1.getLatitudeE6(),
p2.getLatitudeE6())) {
if (p.getLongitudeE6() <= Math.max(p1.getLongitudeE6(),
p2.getLongitudeE6())) {
if (p1.getLatitudeE6() != p2.getLatitudeE6()) {
xinters = (p.getLatitudeE6() - p1.getLatitudeE6())
* (p2.getLongitudeE6() - p1
.getLongitudeE6())
/ (p2.getLatitudeE6() - p1.getLatitudeE6())
+ p1.getLongitudeE6();
if (p1.getLongitudeE6() == p2.getLongitudeE6()
|| p.getLongitudeE6() <= xinters)
counter++;
}
}
}
}
p1 = p2;
}
mStringBuffer.append("\n count is: " + counter);
if (counter % 2 == 0) {
return (false);
} else {
return (true);
}
}
功能很簡單,就是只要在狀態2底下我們點擊地圖,落點在紅色範圍內就是圈內,落點在紅色範圍外就是圈外,判斷為圈內就會有特別的標示和說明。
然後,還有一個也是功能很簡單的程式,就是把InputType類別給全部列出來讓我們調用,
畫面如下:
然後程式碼很蠢,所以就不貼上來分享了。
要注意的,有些type有版本的限制,所以可能會無效,請參考官網說明,
可以試著把Filter by API Level上下調看看就會發現嘍!
不嫌棄的話載點在這裡。
沒有留言:
張貼留言
你好,我是小書,如果文章內容有錯誤,或是看到有建議以及任何感想時,歡迎提出分享,我們一起學習一起努力。