2016-04-14 57 views
1

我嘗試使用谷歌地圖API的Android V2的圖像添加到谷歌地圖:的GoogleMap的GroundOverlayOptions:擠壓圖像四個的LatLngBounds

mMap = googleMap; 
LatLng sw = new LatLng(47.01377857060625, 8.305519705172628); 
LatLng ne = new LatLng(47.01395211967171, 8.306270482717082); 
LatLng nw = new LatLng(47.014014755501165, 8.305559697328135); 
LatLng se = new LatLng(47.01370751919609, 8.306236284552142); 
LatLngBounds latLngBounds = new LatLngBounds(sw, ne).including(nw).including(se); 
GroundOverlayOptions groundOverlayOptions = new GroundOverlayOptions(); 
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromAsset("t2c.png"); 
groundOverlayOptions.image(bitmapDescriptor); 
groundOverlayOptions.positionFromBounds(latLngBounds); 
mMap.addGroundOverlay(groundOverlayOptions); 

不幸的是,LatLng值不是100%準確,所以背景圖像不旋轉但根據Google傾斜:

如果邊界與原始高寬比不匹配,圖像將會傾斜。

只使用LatLngswne

https://developers.google.com/maps/documentation/android-api/groundoverlay#use_latlngbounds_to_position_an_image

With two LatLng

我不知道我應該怎麼能夠找出確切西南部的LatLng和東北,所以我對定義一個多邊形的方式很感興趣,並用四個012來將圖像壓入其中作爲錨點。目前使用四個LatLng看起來像這樣。使用LatLngswnenwse

With four LatLng

回答

0

你將永遠不會達到你想要使用的是什麼的LatLngBounds,因爲你試圖旋轉你的GroundOverlay。

你需要做的是使用地面覆蓋層的方位(旋轉)和寬度/高度。 假設你的建築物旋轉了-20度並且寬高爲40-20(只有你知道這些值) 1-獲得建築物中心的LatLng,它是找到你的四個座標中心上面的代碼。 該值會被你的「centerLocation」

GroundOverlayOptions groundOverlayOptions = new GroundOverlayOptions(); 
BitmapDescriptor bitmapDescriptor = BitmapDescriptorFactory.fromAsset("t2c.png"); 
groundOverlayOptions.image(bitmapDescriptor); 
groundOverlayOptions.position(centerLocation,widthInMeters,heightInMeters); 
groundOverlayOptions.bearing(rotated);//the value is clockwise and rotation is about anchor point (which should be by default 0.5,0.5 of your image 
mMap.addGroundOverlay(groundOverlayOptions); 

這應該工作,很明顯,你必須計算值或走一步看一步嘗試不同的值。

希望它可以幫助

+0

它有助於謝謝,你是否可能知道是否有可能參考這個問題上的觀點圖像不需要GPS LongLat?假設我想在像素座標x = 35/y = 54處在圖像上繪製一些東西。但由於圖像已經旋轉(「軸承」),我不知道如何引用這些點了。 – user3105453

+0

是的,你必須做相對絕對的轉換。 通常情況下,您應該在兩個座標系中選取一對點(左上角,右下角)並找到公式,但在評論中解釋相當複雜,您應該開一個新問題 –