How to set index number on map pin image
I am making a map application in which i have 20 restaurant data and i want to show all restaurant in Map using overlay pin.Now my actual problem is I want to show index number on each and every pin (eg if 20 pin is there ,all pin should be with index no 1,2 ,3 which represent restaurant no from list). can anyone tell me how can i put index number on single pin image..??i want to use same image for overlay
This is a fact I discovered later in my project: MapView
is actually a ViewGroup
(also mentioned here). So instead of using the somehow complicated Overlay and attaching drawables, you can just create a button (or a textview, or some nested layout, or whatever you want to display above a map), assign it a MapView.LayoutParams
instance, and add it to the MapView
.
In code:
// Create the overlay pin
View overlayPin = getLayoutInflater().inflate(R.layout.overlay_pin, null);
// Number it according to your question, e.g.
((TextView)(overlayPin.findViewById(R.id.overlay_text))).setText("1");
Let's say you want to place the pin on geo coordinates -60, 30.
// Set a layout params to the pin.
overlayPin.setLayoutParams(new MapView.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new GeoPoint(-60000000, 30000000), MapView.LayoutParams.BOTTOM_CENTER);
// Add the pin to the map
mapView.addView(overlayPin);
In this way you can have only one graphic asset for the background of the pin, and use a TextView
for the numbering.
You need to extend the drawable class and override onDraw method. In that you can use canvas.drawText to write you number on the pin.
链接地址: http://www.djcxy.com/p/8740.html上一篇: 泛型类型toArray和asList
下一篇: 如何在地图引脚图像上设置索引号