在谷歌Android路线图箭头标记过折线 [英] Arrow Mark over Polyline in Android Google Route Map

查看:492
本文介绍了在谷歌Android路线图箭头标记过折线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何显示箭头超过折线在Android的谷歌地图V2

how to show Arrowheads over Polyline in Android Google map v2

我已经通过几个环节不见了,他们大多给出了链接,JS <一个href="https://google-developers.appspot.com/maps/documentation/javascript/examples/overlay-symbol-arrow" rel="nofollow">https://google-developers.appspot.com/maps/documentation/javascript/examples/overlay-symbol-arrow但我需要在Android中没有JS,我不能使用那些codeS中的Andr​​oid

I have gone through couple of links , most of them gives link to JS https://google-developers.appspot.com/maps/documentation/javascript/examples/overlay-symbol-arrow but I need in Android not JS and I can't use those codes in Android

一些使用MapActivity我也跟着教程来创造地图的活动太多 https://developers.google.com/maps/documentation/android/v1 /你好,图形页面但它没有工作,我不能生成mapactivity,因此我不能使用locationoverlays

Some are using MapActivity I followed a tutorial to creat map activity too https://developers.google.com/maps/documentation/android/v1/hello-mapview but it didnt work I can't generate the mapactivity and thus i couldn't use the locationoverlays

我也得到了一些帖子评论,因为它是在V3可用,但现在我的要求是在V2

i have also got some posts commenting as it is available in v3 but for now my requirement is in v2

这个问题已经被问很多很多次在这里我都知道,但是我找不到任何合适的答案

this question has been asked lot many times here i know but still i couldn't find any proper answer

我怎么能显示一个箭头在多段线,以显示我在哪里应该去的方向

how can i show a arrowhead over the polyline to show the direction where i am supposed to go

任何实例或教程将是非常有益的。

any examples or tutorials will be very helpful.

感谢

推荐答案

在的谷歌地图API V2演示有一个MarkerDemoActivity类,你可以在其中看到的自定义图像是如何设置为GoogleMap的。你可以使用一个标记,以表明这样的箭头:

In the Google Maps API v2 Demo there is a MarkerDemoActivity class in which you can see how a custom Image is set to a GoogleMap. You could use a marker to show the arrowhead like this:

// First you need rotate the bitmap of the arrowhead somewhere in your code
Matrix matrix = new Matrix();
matrix.postRotate(rotationDegrees);
// Create the rotated arrowhead bitmap
Bitmap arrowheadBitmap = Bitmap.createBitmap(originalBitmap, 0, 0,
                      width, height, matrix, true);
// Now we are gonna to add a marker
mArrowhead = mMap.addMarker(new MarkerOptions()
.position(POSITION)
.icon(arrowheadBitmap));

一些澄清: 当你绘制的路线,或者如果你只是得到了两个点来绘制,以获得 rotationDegrees 则可以通过这样做让他们:

Some clarifications: When you are drawing a route, or if you simply got two points to draw, to get the rotationDegrees you can get them by doing this:

rotationDegrees = Math.toDegrees(Math.atan2(originLat-destinyLat, originLon-destinyLon));

经典的旋转游戏算法:D

The classic rotation game algorithm :D

要确保,你箭头图像朝上。需要注意的是,如果你不想使用图像显示箭头和替代那种,你想只使用多段线,就可以实现,通过采取最后的经纬度点(你要去哪里,以显示箭头),并使用通过45°翻译算法,绘制两条线,使箭头。

Be sure of that you arrowhead image is pointing up. Note that if you don't want to use an Image to show the arrowhead and instead of that, you want use only Polylines, you can achieve that by taking the last LatLng point (where you are going to display the arrowhead) and use a translation algorithm by 45º to draw the two lines that make the arrowhead.

这篇关于在谷歌Android路线图箭头标记过折线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆