Google token placement

In my Android app, I need to place the marker in the exact location on the map. I fix the marker on the map with the location 51.507351, -0.127758 (London). To do this, I used the following code.

googleMap.addMarker(new MarkerOptions().position( new LatLng(51.507351, -0.127758)).icon( BitmapDescriptorFactory.fromBitmap(BitmapFactory .decodeResource(getResources(), R.drawable.q_icon)))); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(51.507351, -0.127758), 20)); 

And this is my drawn marker image:

enter image description here

Now my problem is that the character "Q" is located at 51.507351, -0.127758. I need to place the marker where the arrow below starts.

Please see the image so that you can understand my question.

How can i do this? please help me.

enter image description here

+6
source share
4 answers

The logic by which the markers are attached looks something like this:

0,0 0.5,0.0 1,0 *-----+-----+-----+-----* | | | | | | | | | | 0,0.5 +-----+-----+-----+-----+ 1,0.5 | | | X | | (U, V) = (0.7, 0.6) | | | | | *-----+-----+-----+-----* 0,1 0.5,1.0 1,1

Also keep in mind that, based on your raster resource, it may be located a little different than you would expect, because they are actually approaching the closest binding. Therefore, in the example above, your anchor points will be tied to this position: *-----+-----+-----+-----* | | | | | | | | | | +-----+-----+-----X-----+ (X, Y) = (3, 1) | | | | | | | | | | *-----+-----+-----+-----* *-----+-----+-----+-----* | | | | | | | | | | +-----+-----+-----X-----+ (X, Y) = (3, 1) | | | | | | | | | | *-----+-----+-----+-----*

+11
source

Use the MarkerOption anchor method: https://developers.google.com/android/reference/com/google/android/gms/maps/model/MarkerOptions.html#anchor(float,%20float)

In your case:

 MarkerOptions marker = new MarkerOptions() .anchor(0.5f, 1.0f) // Rest of the properties follow 
+7
source

Try the following:

 googleMap.addMarker(new MarkerOptions().position( new LatLng(51.507351, -0.127758)).icon( BitmapDescriptorFactory.fromBitmap(BitmapFactory .decodeResource(getResources(), R.drawable.q_icon))).anchor(0.5f, 1f)); googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom( new LatLng(51.507351, -0.127758), 20)); 
+1
source

Try it,

 private GoogleMap mMap; mMap = ((MapFragment) getFragmentManager().findFragmentById(R.id.map)).getMap(); mMap.addMarker(new MarkerOptions() .position(new LatLng(0, 0)) .title("Hello world") .icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_AZURE))); 
0
source

All Articles