- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在编写一个应用程序,它会显示一张带有一堆标记的 map 。我希望标记是动态的(在其上显示动态内容)。因为标记内容是动态的,所以每个标记的大小都不同。
我在文档中发现“可以为不同的状态返回不同的标记。不同的标记可以有不同的边界。”这里:https://developers.google.com/maps/documentation/android/reference/com/google/android/maps/OverlayItem#getMarker(int)
我假设这意味着同一叠加层上的多个标记可以有不同的大小。对吗?
我的叠加层上有一个 ArrayList(扩展了 BalloonItemizedOverlay)。叠加层的 createItem() 方法如下所示:
@Override
protected OverlayItem createItem(final int index)
{
final Person person = people.get(index);
final GeoPoint gp = new GeoPoint(person.getLat(), person.getLng());
final OverlayItem oi = new OverlayItem(gp, person.getName(), person.getName());
oi.setMarker(new PersonDrawable(defaultMarker, person));
return oi;
}
然后在我的 PersonDrawable
中有一个 drawable,它有一个 9 patch 作为背景图像,然后在它上面绘制文本:
public PersonDrawable(final Drawable iBackground, final Person person)
{
background = iBackground;
text = person.getName();
padding = new Rect();
if (background instanceof NinePatchDrawable)
{
// This is getting hit, and just sets the value of the padding
final NinePatchDrawable ninePatch = (NinePatchDrawable) background;
ninePatch.getPadding(padding);
}
// set the bounds of the marker
bounds = background.getBounds();
paint = new Paint();
paint.setColor(Color.rgb(255, 255, 255));
paint.setFakeBoldText(true);
paint.setTextSize(30);
// find the bounds of the text
final Rect textBounds = new Rect();
paint.getTextBounds(text, 0, text.length(), textBounds);
// set the left and right bounds to that of the text plus the padding (then center it)
bounds.left = 0 - (textBounds.width() / 2) - padding.left;
bounds.right = 0 + (textBounds.width() / 2) + padding.right;
// set the bounds of the drawable
setBounds(bounds);
}
@Override
public void draw(final Canvas canvas)
{
// when it's time to draw, draw the background
background.draw(canvas);
// then draw the text within the padding
canvas.drawText(text, bounds.left + padding.left, bounds.bottom - padding.bottom, paint);
}
每个标记都有一个不同的边界集,即使在它被绘制在叠加层上之后,它的边界也是不同的。 MapView
(或 Overlay
)没有重用 createItem()
中的对象。然而,Overlay
似乎总是选择一个标记并假定这是所有标记的大小。这只是行为吗?我可以做些什么来让它以不同方式尊重每个标记的边界吗?
这里有一些图片,当它决定选择一个更大的标记时,结果没问题:
但是当它选择使用较小的标记作为尺寸时:
最佳答案
问题在于,当从资源中加载Drawable
时,它被视为可共享资源。来自 Drawable
文档:
By default, all drawables instances loaded from the same resource share a common state; if you modify the state of one instance, all the other instances will receive the same modification.
在 OverlayItem
中,假设 Drawable
始终具有相同的大小。您看到的效果是对 Drawable
的最后修改覆盖了所有以前的修改,因此 Drawable
的所有显示都显示完全相同。
解决方案是防止共享 Drawable
的修改。您可以使用 mutate()
方法结合从资源中多次加载 Drawable 来执行此操作。您应该结合上面概述的 PersonDrawable
构造函数来执行此操作。
关于Android MapView自定义标记都是一样大小的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13197725/
我更新了 Android Google Maps v2 示例应用程序中的 RawMapViewDemoActivity.java 以编程方式创建 MapView,但未显示 map 。我只是得到一个空白
我需要一个禁用所有手势的 MapView。它基本上只是 fragment 中的一个小 View ,当您按下它时,它会转到 LocationPickerFragment。我认为我没有以正确的方式做这件事
我试图通过函数在 mapView 上放置一些注释,但 mapView 在调试器中显示为 nil。我从不同的类调用下面的函数,调用似乎通过设置一些断点来工作。它只是在尝试将注释数组添加到 mapView
我刚刚构建了一个 swift 应用程序,它从 dynamoDB 获取 data+coords 并将其放到 ios mapkit 上。有两组坐标:一组用于当前用户位置,一组来自dynamoDB。我希望这
我在屏幕的一角有一个 Google map View 。我想添加一个事件,使其通过 map 界面上的按钮进入全屏,然后再次使用相同的按钮进入小屏幕。有什么想法吗?? 安卓 v4.0.4谷歌地图 API
问题 我有一个包含全屏 MKMapView 的 View 。 MapView 的下半部分覆盖有具有半透明单元格的 TableView,以便 map 显示。 当我以注释坐标为中心时,例如当前位置,注释
我如何从 React-Native 中 MapView 组件的纬度和经度值计算 delta-latitude 和 delta-longitude 值。谢谢你 最佳答案 如果您有一个坐标数组并且您想要一
为什么 CameraUpdateFactory 类在我的项目中不起作用? 如果执行以下命令,应用程序会崩溃: CameraUpdate pino= CameraUpdateFactory.newLat
我搜索了这个问题,发现了一些关于相同但不知道如何解决问题的 stackoverflow 问题。 我创建了一个 Activity ,我想添加一个非常小的 map View (例如 140w X 70h)
我在 android 市场上有一个应用程序,它使用 mapview 来显示一些位置。这在我测试过的所有设备上都能正常工作。将其转换市场一段时间后,我看到有几个人报告了一个问题。 map View 不拼
我在谷歌地图中用标记绘制了路径。所以路径是静态的,但标记需要改变它们的位置。如何在不使用 mapview.clear() 的情况下删除所有标记,因为它也会从 map 上清除我的路径。 有什么解决办法吗
在使用 react-native-maps 的 native 应用程序中,我试图以编程方式显示 MapView.Callout特定的 MapView.Marker在许多之中。我打算使用 showCal
我将尝试在名为 RoeteFragment 的 fragment 上显示我的 Android 应用程序中的 map 。如果我调试我的代码,我会看到方法 onMapReady 从未被调用,因此 map
我正在使用 mapbox 和 firebase。我有一个委托(delegate)函数,当用户的位置发生变化时,它会更新用户的坐标(在 firebase 数据库内部)。据我所知,它在登录到应用程序后可以
我在 SwiftUI 中使用 GMSMapView,在 map View 中我必须显示一些带有经纬度的标记。单击任何标记后,我必须移动到另一个 View 。我这样做是通过将 MapView 放入 导航
我想找到一种简单的方法来获取路线。有没有办法用mapview来做到这一点?下面是我当前的代码。 - (IBAction)goToMap:(id)sender { [self.view addSubvi
我正在尝试为 map 创建自定义注释。我遇到的问题是,我无法使注释一个接一个地删除。所有销钉同时落下。这是 didAddAnnotations 的委托(delegate)代码。你能帮我重写代码,以便我
我正在制作一款 iPhone 应用程序,该应用程序专为密苏里州本地的事物而设计。所以我的想法是将 map 限制为仅密苏里州/靠近密苏里州的地区。我的 map 工作正常,显示用户的位置,如果他们更新位置
是否可以让嵌入的 MKMapView 旋转以始终面向 iPhone 所面向的方向?基本上我想在我自己的应用程序上模仿 map 应用程序旋转功能。 我发现 iPhone SDK 没有公开该功能。但是,我
我已加载用户当前位置的自定义注释图像。我将在后台每 1 秒更新一次当前用户位置。 NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
我是一名优秀的程序员,十分优秀!