How to set the index number on the map

I am making a map application in which I have 20 data in a restaurant and I want to show the whole restaurant on a map using an overlay. Now my real problem is that I want to show the index number on each pin (for example, if there is a 20-pin one, all contacts should be with the index number 1,2, 3, which do not represent the restaurant from the list). can someone tell me how i can put index number on one pin image. I want to use the same image for overlay

+7
source share
2 answers

This is a fact that I discovered later in my project: MapView is actually a ViewGroup ( also mentioned here ). Therefore, instead of using complex Overlay and attaching drawings, you can simply create a button (or text view, or a nested layout, or whatever you want to display above the map), assign it an instance of MapView.LayoutParams and add it to MapView .

In code:

 // Create the overlay pin View overlayPin = getLayoutInflater().inflate(R.layout.overlay_pin, null); // Number it according to your question, eg ((TextView)(overlayPin.findViewById(R.id.overlay_text))).setText("1"); 

Suppose you want to put the output 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); 

That way, you can only have one graphic asset for the pin background and use the TextView for numbering.

+3
source

You need to extend the drawable class and override the onDraw method. In this case, you can use canvas.drawText to write the number on the output.

0
source

All Articles