[英]Drawing a circle on google maps static link
根據此SO答案https://stackoverflow.com/a/38100481/1520234 ,我嘗試通過向getCircleAsPolyline
提供Location
數據,然后使用PolyUtil.encode
進行編碼,在靜態地圖上繪制圓。
不幸的是,輸出結果不是一個圓,而是類似以下內容:
有人可以請我解釋為什么會這樣嗎,是否有可能形成一個真正的圈子,如果是這樣,怎么做?
謝謝
編輯
抱歉,我不太清楚,我忘了提到我的getCircleAsPolyline
與鏈接的對象略有不同,因為我使用SphericalUtil.computeOffset
來計算坐標; 無論如何,下面是我的getCircleAsPolyline
函數:
private static ArrayList<LatLng> getCircleAsPolyline(Location center, float radius) {
ArrayList<LatLng> circlePath = new ArrayList<>();
double step = 5.0;
double centerLatitude = center.getLatitude();
double centerLongitude = center.getLongitude();
for (double angle = 0.0; angle < 360.0; angle += step) {
LatLng circlePoint = SphericalUtil.computeOffset(
new LatLng(centerLatitude, centerLongitude),
radius,
(90.0 - angle + 360.0) % 360.0
);
circlePath.add(circlePoint);
}
return circlePath;
}
但結果是圖片中顯示的那個
對於那些來這里也遇到相同問題的人,我只是避免了對折線進行編碼:只要我放下PolyUtil.encode並將點附加為|,就有效。 長,經度| 我已經能夠畫出一個完美的圓圈。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.