java - 访问 map 中MyLocation蓝点的可绘制资源

标签 java android xml google-maps-markers google-maps-android-api-2

我希望获得与 map 上指示您的位置和方位(蓝色)的圆圈相同的纹理,以便添加具有相同纹理和行为的其他圆圈(红色)。

我有什么:

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

我使用了 map.addCircle 来获取下面显示的结果。

What I managed to do

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

需求:

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

显示方位至关重要。

具有精确指示(宽圈可选)。

编辑1:

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

编辑2:

使用应用程序资源(在PlayStore上提供),我发现 map 的drawable文件夹中存在blue_dot。所以我尝试了:

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

但是我得到了一个无法解析符号...有什么想法吗?

编辑 3...:

为了完成我之前所说的内容,这里有一个屏幕截图,显示资源位于 map 可绘制对象中: Screenshot of App's Ressources Application available on PlayStore

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

Suggestions in Android Studio

最佳答案

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

创建一个资源,该资源是一个点(根据需要蓝色或红色),并且其顶部有“方位”指示器(如标准资源),然后将“箭头”指向该资源的上中心部分资源。 将其作为标记资源,将其设置为平面( setFlat(boolean flat) )并根据所需的方位更改旋转;来自文档:

Rotation

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.

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

setAnchor( float anchor U, float anchor V)

文档是 https://developers.google.com/android/reference/com/google/android/gms/maps/model/Marker#setAnchor(float, float)

将点置于资源中心更容易,但资源会更大。

关于发光 这是“更糟糕”的做法,因为你不能以与他们相同的方式绘制它(同样,我假设他们没有使用标准 API,我不知道)。 您可以添加一个中心与标记相同的圆形,并稍微调整一下颜色和圆形尺寸:

// 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 并在缩放时调整标记的大小(这是一个困惑的好方法!)

关于java - 访问 map 中MyLocation蓝点的可绘制资源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31270239/

相关文章:

java - Spring MVC Controller 请求映射无法正常工作

Java Swing - 使用 AbstractTableModel() 从表中删除行

ruby - 你如何处理 Savon 中的嵌套命名空间?

android - 如何使用 mapbox android 删除 map 上的所有标记?

android - 如何将数据绑定(bind)与 ProgressBar 结合使用?

xml - XML 中是否可以有多个命名空间前缀?

java.lang.IllegalArgumentException : InputStream to parse is null

java - 标准 Kotlin 库中有哪些 Java 8 Stream.collect 等效项?

java - JFrame 按钮和 GridBagConstraints

android - 如何在 Android Activity 中实现 'Remember me' 函数?