在Google Maps API v2中添加自定义视图作为标记

3

I've developed a class that inherits from a View class and I want it to serve as a marker on a MapFragment/MapView from a Google Maps API v2. As I recall, such thing was possible in API v1 and even now it is possible on iOS. I'm looking for something like this:

MapView map = (MapView)findViewById(R.id.mapview);
CircleTimerView myTimer = new CircleTimerView(this);
LayoutParams lp = new LayoutParams(iv.getWidth(), iv.getHeight(), geoPoint, LayoutParams.BOTTOM);
map.addView(myTimer,lp);

My custom View is animated and it is a key feature of my app.

My question is: Is it possible for a current state of Google Maps API? Or should I try to obtain API v1 key and work with something that was deprecated?

Thanks in advance for your replies.

3个回答

2

我应该尝试获取API v1密钥并使用已被弃用的内容吗?

您无法获取API v1的新密钥。

我的自定义视图是动画的,这是我的应用程序的关键特性。

除非您反复使用Marker.setIcon更改图标,否则您无法拥有带有动画的Marker图标。

当前状态下是否可以使用Google Maps API?

如果您首先将其绘制到Bitmap中,则可以将View用作图标。 Chris Broadfoot的此库可以大大帮助您完成此任务:

https://github.com/googlemaps/android-maps-utils

查看此视频以了解该库的功能:http://www.youtube.com/watch?v=nb2X9IjjZpM

或者访问新网站:http://googlemaps.github.io/android-maps-utils/


那是一个很好的建议,非常感谢你,Maciej。如果这对我有用,我会告诉你的。 - kazalagoopagoo

0
为了在Google Maps API V2上自定义/使用自己的定制标记,您可以编写以下代码:
在onCreate中声明标记:
    userIcon = R.drawable.red;

然后我在需要的地方使用了它,在我的情况下,我把它用在一个方法中:

    if(userMarker!=null) userMarker.remove();

    userMarker = theMap.addMarker(new MarkerOptions()
    .position(lastLatLng)
    .title("You are here")
    .icon(BitmapDescriptorFactory.fromResource(userIcon))
    .snippet("Your last recorded location"));
    theMap.animateCamera(CameraUpdateFactory.newLatLng(lastLatLng), 100, null);

    CameraUpdate center=
            CameraUpdateFactory.newLatLng(lastLatLng);
        CameraUpdate zoom=CameraUpdateFactory.zoomTo(15);
       theMap.moveCamera(center);
        theMap.animateCamera(zoom);

希望这有所帮助。祝你好运。

0

我最近也遇到了同样的问题,你应该切换到v2,因为你可以更容易地完成所有与v1相同的操作,而且还有许多新功能。

MapView已被新的GoogleMap-Object类型所取代。

一个非常详细和不错的教程网站可以在这里!找到。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接