Android Google Maps v2: customized marker with large click area - java

Related: Customizing clickable area on a Marker in Google Maps v2 for Android
I have a number of icons inside an ArrayList, which are all custom icons with a drawable. The problem I have is that the clickable area is that of the default marker. I need to customize this clickable area to the same size of the default marker.
Here is my code to generate a set of markers on the map:
MarkerOptions options = new MarkerOptions();
for (Icon iconItem: icons) {
//Scale icon
int markerSize = 90;
Bitmap iconBitmap = BitmapFactory.decodeResource(getResources(), iconItem.resourceInt);
Bitmap scaledIconBitmap = Bitmap.createScaledBitmap(iconBitmap, markerSize, markerSize, false);
options.position(iconItem.location).title(iconItem.type);
Marker newMarker = gMap.addMarker(options);
newMarker.setIcon(BitmapDescriptorFactory.fromBitmap(scaledIconBitmap));
}

Related

Change Google Map's axis of rotation

I am using Google Map API in an Android app and trying to rotate the map. I have already done it by changing the bearing value but the problem is that it rotates around the center of the screen.
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.animateCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
I want to change its axis of rotation and make it rotate around a point at bottom of screen
Is there any function to change the axis of rotation of the map?
Anyway, you can use workaround like that - move map rotation center point to bottom of screen by creating MapView (MapFragment) twice as wide and as high and using margins align it position to center bottom like on a figure below:
In that case, with default:
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.animateCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
your mainMap will turn around center of bottom of screen.
UPDATE:
Also you can use get current map center screen coordinates, then change y coordinate and get new screen center. Something like that:
...
CameraPosition bottomPos = new CameraPosition.Builder()
.bearing(bearing)
.build();
mainMap.moveCamera(CameraUpdateFactory.newCameraPosition(bottomPos));
LatLng mapCenter = mainMap.getCameraPosition().target;
Projection projection = mainMap.getProjection();
Point centerPoint = projection.toScreenLocation(mapCenter);
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
int displayHeight = displayMetrics.heightPixels;
centerPoint.y = centerPoint.y - displayHeight / 2; // move center down
LatLng newCenterPoint = projection.fromScreenLocation(centerPoint);
mainMap.animateCamera(CameraUpdateFactory.newLatLngZoom(newCenterPoint, zoom));
...

Google maps custom marker too large [duplicate]

This question already has answers here:
Change marker size in Google Maps API v2
(5 answers)
Closed 4 years ago.
I am adding a custom marker to my map with code
marker =new MarkerOptions().icon(BitmapDescriptorFactory.fromResource(R.drawable.bus)));
but it appears too large and covers the whole screen
how to solve this issue.
you can resize programmatically
Solution 1:
int height = 100;
int width = 100;
BitmapDrawable bitmapdraw=(BitmapDrawable)getResources().getDrawable(R.drawable.bus);
Bitmap b=bitmapdraw.getBitmap();
Bitmap smallMarker = Bitmap.createScaledBitmap(b, width, height, false);
MarkerOptions marker = new MarkerOptions()
.title("Your title")
.icon(BitmapDescriptorFactory.fromBitmap(smallMarker));
googleMap.addMarker(marker);
Solution 2:
Simple you need to Change your Image into Small size.

How to add multiple markers with an array of geopoints on android?

I need to add a list of geopoints as markers on top of my custom OSM map in my android device, the below code is a sample for showing up one marker.
GeoPoint startPoint = new GeoPoint(48.13, -1.63);
Marker startMarker = new Marker(map);
startMarker.setPosition(startPoint);
startMarker.setAnchor(Marker.ANCHOR_CENTER, Marker.ANCHOR_BOTTOM);
map.getOverlays().add(startMarker);

Keep Size Image with Ground Overlay in Google Map

I'm new in Android and I'm building an app. My problem is that when I want to put my own image in google map app using Ground Overlay.
But When I put my images, I can't keep the size, it very small and when I zoom it is the real size. What I would like to have it's when I zoom it keep the same size.
For example in Booking App, The "H" image is always at the same size (Airbnb had the same also).
Here is my code:
#Override
public void onMapReady(GoogleMap map) {
// Register a listener to respond to clicks on GroundOverlays.
map.setOnGroundOverlayClickListener(this);
map.moveCamera(CameraUpdateFactory.newLatLngZoom(NEWARK, 11));
mImages.clear();
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_nj_1922));
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.newark_prudential_sunny));
mImages.add(BitmapDescriptorFactory.fromResource(R.drawable.logo_franprix));
//Resources res = getResources();
//Drawable drawable = res.getDrawable(R.drawable.ic_logo_franprix);
// Add a small, rotated overlay that is clickable by default
// (set by the initial state of the checkbox.)
mGroundOverlayRotated = map.addGroundOverlay(new GroundOverlayOptions().image(mImages.get(2)).anchor(0, 1)
.position(new LatLng(48.886517, 2.37105), 300f,300f));
I hope that you could help me, thank you very much.

android - How to add satellte image in osmdroid

I get a .png from my server that represents a satellite image and I would put this image like a layer over the OpenStreetMap so I can see the street (under the satellite image) and the aerial photo on the same map.
I use this method
Drawable d = new BitmapDrawable(getResources(), bitmap);
bb = map.getBoundingBox();
Location SO = new Location(LocationManager.GPS_PROVIDER);
SO.setLatitude(bb.getLonWest());
SO.setLongitude(bb.getLatSouth());
Location NO = new Location(LocationManager.GPS_PROVIDER);
NO.setLatitude( bb.getLonWest());
NO.setLongitude(bb.getLatNorth());
Location NE = new Location(LocationManager.GPS_PROVIDER);
NE.setLatitude(bb.getLonEast());
NE.setLongitude(bb.getLatNorth());
float height = SO.distanceTo(NO);
float width = NE.distanceTo(NO);
Projection projection = map.getProjection();
int y = map.getHeight() / 2;
int x = map.getWidth() / 2;
GeoPoint geoPoint = (GeoPoint) projection.fromPixels(x, y);
deleteLayers(GroundOverlay.class);
GroundOverlay myGroundOverlay = new GroundOverlay();
myGroundOverlay.setImage(d);
myGroundOverlay.setPosition(geoPoint);
myGroundOverlay.setDimensions(width*0.94f, height*1.06f);
map.getOverlays().add(myGroundOverlay);
map.invalidate();
the problem is that the image always is stretch. my png cover only a part of my map (and it's ok beacuse our png is this way). When i move in the map the image stretching in all map but and it cover a part of map that it not rappresent.
Also, the image is not in the right place (look the red arrow).
How can i fix it?
Assuming your satellite image is limited to a portion of map you can use osmbonuspack GroundOverlay.
Probably this issue: https://github.com/MKergall/osmbonuspack/issues/273
Look at the hint about corrective coefficients.

Categories