在地图中访问MyLocation蓝点的可绘制资源 [英] Access the drawable resource of MyLocation blue dot in Maps

查看:113
本文介绍了在地图中访问MyLocation蓝点的可绘制资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想获得与指示您在地图上的位置和方位(蓝色)的圆圈相同的纹理,以便添加具有相同纹理和行为的其他圆圈(红色).

I would like to get the same texture as the circle that indicates your position and bearing (blue) on the map in order to add other circles (in red) with the same texture and behaviour.

我可以访问所有与红点有关的参数:LatLng, Bearing ...

I have access to all the params concerning the red point : LatLng, Bearing...

我使用map.addCircle来获得下面显示的结果.

I used a map.addCircle to get the result displayed below.

map.addCircle(new CircleOptions()
            .center(position1)
            .fillColor(Color.RED)
            .strokeColor(Color.WHITE)
            .radius(1.2)
            .strokeWidth(1 / 4));

需要:

我需要使圆独立于倾斜度和缩放,即其大小适应缩放级别,并且其行为就像蓝色的圆.

Needs:

I need the circle to be independant of the tilt and independant of the zoom, ie its size adapts to the zoom level and it behaves just like the blue circle.

显示方位是必不可少的.

Having the bearing displayed is essential.

具有精度指示(粗圆圈是可选的).

Having the precision indication (the wide circle is optional).

我认为此蓝点可能位于com.google.android.gms.maps.R.drawable目录中,但我找不到获取信息或访问绘图对象列表的方法

I think that this blue dot may be in the com.google.android.gms.maps.R.drawable directory but I can't find a way to get the info, or to get access to the list of drawables !

使用 Apps资源(可在PlayStore上找到,我发现Maps的可绘制文件夹中存在blue_dot.因此,我尝试了:

Using Apps Ressources (available on the PlayStore, I came to find that a blue_dot exists in the drawable folder of Maps. So I tried :

.icon(BitmapDescriptorFactory.fromResource(com.google.android.gms.maps.R.drawable.blue_dot)

但是我得到了无法解析符号 ......知道吗?

But I got a Cannot Resolve Symbol... Any idea ?

为完成我之前所说的,以下是一个屏幕截图,显示资源位于Maps绘制对象中:

To complete what I was saying before, here is a screenshot showing that the ressources is in the Maps drawables:

这是我的AndroidStudio中似乎可用的可绘制对象的列表:

And this is the list of drawables that seem available in my AndroidStudio :

推荐答案

您无法访问蓝点资源,因为它不是公共资源.无论如何,它是一个蓝点,其中带有轴承的部分已作为资源的一部分添加. 我们不知道如何创建它(没有解释或源代码),但是您可以尝试通过以下方式复制它:

You can't access the blue dot resource because it is not public. Anyway it is a blue dot with the bearing part added as part of the resource. We can't know how to create it (there is no explanation or source code), but you can try to replicate it by:

创建一个资源(该资源是一个点(根据需要是蓝色或红色),并且具有轴承").指示器上方(与标准指示器一样),然后将箭头"指向资源的中上部分. 将其作为标记资源,将其放置为平面(setFlat(boolean flat)),然后根据所需的方位更改旋转;从文档中:

Create a resource which is a dot (blue or red as you want) and that have the "bearing" indicator on top of it (like the standard one), and put the 'arrow' to point the up center part of the resource. Se this as a marker resource, put it as flat ( setFlat(boolean flat) ) and change the rotation according to the bearing you want; from the documentation:

旋转

标记围绕标记沿顺时针方向旋转的角度 标记的锚点.旋转轴垂直于 标记.旋转0对应于默认位置 标记.当标记在地图上平坦时,默认位置是 北对齐,旋转使标记始终保持 平在地图上.当标记是广告牌时,默认位置 指向上方,旋转使得标记始终 面对镜头.默认值为0.

The rotation of the marker in degrees clockwise about the marker's anchor point. The axis of rotation is perpendicular to the marker. A rotation of 0 corresponds to the default position of the marker. When the marker is flat on the map, the default position is North aligned and the rotation is such that the marker always remains flat on the map. When the marker is a billboard, the default position is pointing up and the rotation is such that the marker is always facing the camera. The default value is 0.

您必须注意锚点"标记的位置,必须将其设置为点的中心,而不是资源的中心(否则它将无法正常工作).为此,请将点放置在资源的中心(根据方位箭头尺寸)或在添加标记时更改锚点:

You have to pay attention to the "anchor" of the marker, which must be set to the center of the dot, not the center of the resource (otherwise it will not work correctly). In order to do it, place the dot in the center of the resource (according to the bearing arrow dimension) or change the anchor when adding the marker:

setAnchor(浮动锚U,浮动锚V)

setAnchor (float anchorU, float anchorV)

文档为在资源中将圆点居中比较容易,但是资源会更大.

It is easier to center the dot in the resource, but the resource will be bigger.

关于发光 这是较差"的.因为您不能以与他们相同的方式绘制它(同样,我想他们不使用标准API,我也不知道). 您可以添加一个中心,使其与标记相同的圆形,并使用颜色和圆形尺寸来发挥作用:

About the glow This is "worse" to do since you can't draw it in the same way they do (again, I'm supposing they are not using standard API, I can't know). You can add a circle shape with center the same as the marker and play a bit with colors and circle dimensions:

// Instantiates a new CircleOptions object and defines the center and radius
CircleOptions circleOptions = new CircleOptions()
    .center(new LatLng(POS_LAT, POS_LNG))
    .radius(30) // radius in meters
    .fillColor(0x8800CCFF) //this is a half transparent blue, change "88" for the transparency
    .strokeColor(Color.BLUE) //The stroke (border) is blue
    .strokeWidth(2)); // The width is in pixel, so try it!

// Get back the mutable Circle
Circle circle = myMap.addCircle(circleOptions);

我唯一不能做的就是缩小时点的尺寸.不幸的是,gmaps会自动调整其大小,因此,为了使其变小,您必须使用GoogleMap.OnCameraChangeListener并在缩放时调整标记的大小(这样做很麻烦!)

The only thing i can't help is on the dimension of the dot when zooming out. Unfortunately gmaps automatically resize it, so in order to keep it small, you have to work with the GoogleMap.OnCameraChangeListener and resize the marker when zooming (this is a mess to do in a good way!)

这篇关于在地图中访问MyLocation蓝点的可绘制资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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