1

I'm working on a maps based app, the user has the generic Google Maps interface, but I want to add a 3d custom element on an event. A user can add a pokestop (that is my element for example) on the map only with a button press.

I'm working with the Google Maps API, but I don't know if I should use a graphics engine. Actually, I don't want to use Unity or other engine; I want to make the app as light as possible.

The app should run on android. Do you have any suggestions?

Ed Rands
  • 911
  • 12
  • 19
Licat
  • 11
  • 1
  • This might help you. http://stackoverflow.com/questions/14811579/how-to-create-a-custom-shaped-bitmap-marker-with-android-map-api-v2 – Deepank Dwivedi Nov 20 '16 at 21:39

1 Answers1

0

To create a marker with an image use this. // Uses a custom icon.

mSydney = mMap.addMarker(new MarkerOptions()

.position(DELHI)

.title("Delhi")

.snippet("Population: 86,398,800")

.icon(BitmapDescriptorFactory.fromResource(R.drawable.image)));

To use a a canvas,

Bitmap.Config conf = Bitmap.Config.ARGB_8888;

Bitmap bmp = Bitmap.createBitmap(80, 80, conf);

Canvas canvas1 = new Canvas(bmp);

// paint defines the text color, stroke width and size

Paint color = new Paint();

color.setTextSize(35);

color.setColor(Color.BLACK);

// modify canvas

canvas1.drawBitmap(BitmapFactory.decodeResource(getResources(),

R.drawable.user_picture_image), 0,0, color);

canvas1.drawText("User Name!", 30, 40, color);

// add marker to Map

mMap.addMarker(new MarkerOptions().position(USER_POSITION)

.icon(BitmapDescriptorFactory.fromBitmap(bmp))

// Specifies the anchor to be at a particular point in the marker image.

.anchor(0.5f, 1));

Using this you can Draw Fancier stuffs.

In the Google Maps API v2 Demo there is a MarkerDemoActivity class in which you can see how a custom Image is set to a GoogleMap.

// Uses a custom icon.

mSydney = mMap.addMarker(new MarkerOptions()

.position(SYDNEY)

.title("Sydney")

.snippet("Population: 4,627,300")

.icon(BitmapDescriptorFactory.fromResource(R.drawable.arrow)));

As this just replaces the marker with an image you might want to use a Canvas to draw more complex and fancier stuff:

Bitmap.Config conf = Bitmap.Config.ARGB_8888;

Bitmap bmp = Bitmap.createBitmap(80, 80, conf);

Canvas canvas1 = new Canvas(bmp);

// paint defines the text color, stroke width and size

Paint color = new Paint();

color.setTextSize(35);

color.setColor(Color.BLACK);

// modify canvas canvas1.drawBitmap(BitmapFactory.decodeResource(getResources(),

R.drawable.user_picture_image), 0,0, color);

canvas1.drawText("User Name!", 30, 40, color);

// add marker to Map

mMap.addMarker(new MarkerOptions().position(USER_POSITION)

.icon(BitmapDescriptorFactory.fromBitmap(bmp))

// Specifies the anchor to be at a particular point in the marker image.

.anchor(0.5f, 1));

This draws the Canvas canvas1 onto the GoogleMap mMap. The code should (mostly) speak for itself, there are many tutorials out there how to draw a Canvas. You can start by looking at the Canvas and Drawables from the Android Developer page.

Now you also want to download a picture from an URL.

URL url = new URL(user_image_url);

HttpURLConnection conn = (HttpURLConnection) url.openConnection();

conn.setDoInput(true);

conn.connect();

InputStream is = conn.getInputStream();

bmImg = BitmapFactory.decodeStream(is);

You must download the image from an background thread (you could use AsyncTask or Volley for that).

After that you can replace the BitmapFactory.decodeResource(getResources(), R.drawable.user_picture_image) with your downloaded image bmImg.

  • Thanks for the answer, but if I want to add an animation (like the flowers on the pokestop) on my custom marker, how I should proceed? – Licat Nov 21 '16 at 13:36