2016-04-14 37 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

是的,你必须做相对绝对的转换。 通常情况下,您应该在两个坐标系中选取一对点(左上角,右下角)并找到公式,但在评论中解释相当复杂,您应该开一个新问题 –