I would like to change the colors of the areas of Google Maps.
Here's an example
Is there a way I could do that?
Hi you can use Polygon for draw shape.
https://developers.google.com/android/reference/com/google/android/gms/maps/model/Polygon
Another possible way is GroundOverlay.
You can overlay an image for particular area over the map (under markers, polygons, polylines).
https://developers.google.com/maps/documentation/android-api/groundoverlay
update: How to create a ground overlay layer?
For example: you want to fill this building as green.
You need to get latitude and longitude pairs for two positions : southwest and northeast.
Then create an image with transparent (such as PNG format).
After that, you need to create a ground overlay in your code.
LatLngBounds bounds = new LatLngBounds(
new LatLng(....), // South west corner
new LatLng(....) // North east corner
);
GroundOverlayOptions myBuilding = new GroundOverlayOptions()
.image(BitmapDescriptorFactory.fromResource(R.drawable.my_building))
.positionFromBounds(bounds);
You should see the target building is painted as green.
Related
I'm using a MapView to display a Google Map and the trying to create a circle overlay. But for some reason the circle border is displayed but it is not filled with any color, here is what is generated using the android emulator:
Here is an idea of what I would like to achieve (i created it through the w3school online editor).
Here is the code:
LatLng center = new LatLng(-16.272425327210556,166.4380745618525);
double radius = 9944545.500957435;
CircleOptions co = new CircleOptions().center(center).clickable(false).radius((radius)).fillColor(Color.YELLOW).visible(false);
this.marker_twilight_civil = map.addCircle(co);
I tried with a different radius value and actually it works with a specific one, here i created 3 circles with different radius values, and olny one is filled, the other two are not filled.
Here is the code for the circle that is filled correctly
LatLng center = new LatLng(-16.272425356472187,166.43807456511806);
double radius = 8006044.77150472;
CircleOptions co = new CircleOptions().center(center).clickable(false).radius((radius)).fillColor(Color.GREEN).visible(true);
this.marker_night = map.addCircle(co);
Could it be a issue with the too large radius? But on the web version is working well.
It could be because the radius is too large. Google Maps uses a Mercator projection, which will skew circles if they are large enough. For technical reasons, if the shape isn't "closed" then the fill won't be applied. If the shape is too large, or too close to the highly-skewed top or bottom of the map, then the shape will break open and the fill will be ignored.
If it was truly important you could try forcing a custom Projection on Google Maps (which could avoid the skew and keep the shape closed), but this isn't a well-tread path and I can't provide a solution beyond the link:
https://developers.google.com/maps/documentation/javascript/examples/map-projection-simple
I have a list of coordinates (yLat, xLon) with an angle (bearing in degrees, e.g. 160) to draw on my map, and I would like to do it with lines or arrows which start from the coordinates and head to the bearing.
I started to do it using a Polyline:
LatLng thisPoint = new LatLng(yLat, xLon);
Polyline site = googleMap.addPolyline(new PolylineOptions()
.add(thisPoint, new LatLng(11.593, 104.932))
.width(5)
.color(Color.MAGENTA));
However the line is too small when I zoom out: I want the line to be always the same size on the screen to show the direction to the user and independently of the zoom level.
See the example below: on the first screenshot the magenta line is big enough, but on the second one after zooming out, the line becomes smaller and we cannot see the direction as clearly.
Any suggestion?
I found the best way to address my need: I created a marker with an icon with a vertical arrow in the middle of a transparent square (R.mipmap.ic_arrow_up), then I create the marker applying a rotation of the desired angle:
googleMap.addMarker(new MarkerOptions()
.position(myLatLng)
.title(myTitle)
.snippet(mySnippet)
.icon(BitmapDescriptorFactory.fromResource(R.mipmap.ic_arrow_up))
.rotation(myAngle));
Hope this helps other people
I'm new to android.
I can add a map and add a point on it, but How can I change the color of a specific area of road in Google Maps?
Like the picture
I wanna set OnClickListener for area 1 to 4 and create log for the position of that area
thanks
If you have latlng of the start point and destination point, you can draw polylines:
PolylineOptions polyOptions = new PolylineOptions();
polyOptions.color(ContextCompat.getColor(context, R.color.colorPrimary));
polyOptions.width(10);
polyOptions.add(startLatLng, latLngDestination);
I am moving from Android googlemap v1 to v2. I found that to display my own icons I have to use GroundOverlay(In v1 I used Overlay ) Is there any other good solution?
Can I update the GroundOverlay location whenever I receive the location updates? (move the object) Google says "A ground overlay is an image that is fixed to a map"
Even if I add GroundOverlay I don't see it in my map. It just locate to Africa. No Icon. When I add Marker I can see that. But not GroundOverlay.
BitmapDescriptor image =
BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE);
LatLngBounds bounds = new LatLngBounds (new LatLng(00.00, 00.00), new LatLng(00.00, 00.00)); // get a bounds
GroundOverlayOptions goo = new GroundOverlayOptions();
goo.image(image);
goo.positionFromBounds(bounds);
goo.transparency(0);
goo.visible(true);
// Adds a ground overlay with 50% transparency.
GroundOverlay groundOverlay = googleMap.addGroundOverlay(goo);
I have a demo in 2 days I really want this to work. Please help.
I found the problem. The problem is with the zoom. The GroundOverlay is very small to see.
final LatLng cordination = new LatLng(40.714086, -74.228697);
goo.position(cordination, 500000f);
Now my problem is when I zoom the map. The GroundOverlay also zooming. I want this not to zoom and work like a Marker. Any one know how to do Pls respond.
The ground overlay is something that behaves as if it is laying on the ground. So it will be turned, zoomed etc. together with the map.
So why do you prefer ground overlay over markers if you want to work it like a marker? You can use your own image also for a marker:
BitmapDescriptor image = ....;
MarkerOptions options = new MarkerOptions();
options.position(coordinate);
options.icon(image);
googleMap.addMarker(options);
In APIv1 I was drawing markers like this:
Drawable flag = getResources().getDrawable(R.drawable.flagfinish);
flag.setBounds(0, -flag.getIntrinsicHeight(), flag.getIntrinsicWidth(), 0);
and it was working - left bottom corner of picture was in center of LatLng. But how could I draw something like this in APIv2? I tried this:
Marker hc = mMap.addMarker(new MarkerOptions()
.position(HC)
.title("Hlohovec")
.snippet("Hlohovec")
.icon(BitmapDescriptorFactory.fromResource(R.drawable.flagfinish)));
but this is moved to left (I want to draw a flag with pole on left so this doesn't pin it where I want).
Is there any possible way to do this? And I don't want to use GroundOverlayOptions because it is changing with zoom.
Thanks for any answers.
you need to change the Anchor position of the marker image when you create the marker
from the docs:
The point on the image that will be placed at the LatLng position of the marker. This defaults to the middle of the bottom of the image.