Custom marker is not drawn on some devices - android

I wanted to draw a marker on Google map based on some location data I collected. When I tested the code using Galaxy S5 it draws the marker but when I try to do the same thing using a Motorola it fails to draw the marker at times and draws it other times. The object the marker represents is always there even in the Motorola. The Galaxy runs Android 5.1.1 and the Motorola 5.1: the code is as follows.
private MarkerOptions getMarkerForItem(Provider pro, LatLng lctionll, float brng){
MarkerOptions mo = new MarkerOptions();
isMarkerAlive = true;
mo.icon((BitmapDescriptorFactory.fromResource(R.drawable.cuteMarker)))
.anchor(0.5f, 0.5f) //so marker rotates around the center
.position(lctionll)
.rotation(brng)
.flat(true);
return mo;
}
There is similar question in SO but there is no answer regarding the hardware differences and how to deal with these issues. Can someone help?
EDIT---> The Galaxy has Google play services 9.2.56 and the Motorola has 9.4.52

Adding .visible(true) fixed it in the Motorola phone. I will test other devices and update this answer as needed.
MarkerOptions mo = new MarkerOptions().icon((BitmapDescriptorFactory.fromResource(R.drawable.movingcab)))
.anchor(0.5f, 0.5f) //so marker rotates around the center
.position(lctionll)
.rotation(brng)
.visible(true)
.flat(true);

Related

LatLngBounds with CameraUpdate not zooming in

I have a GoogleMap (Lite Mode) object that has been properly initialized. It works properly with a single Marker and focuses on the proper area using CameraUpdate with newLatLngZoom.
However, when it comes to adding two markers, and have the map keep both in view using LatLngBounds, everything goes bonkers. The map is so zoomed out it shows the entire continent, and the two markers are on-top of each other (along with the polyline).
Kindly assume that the data from the pickup and destination is correct
Here's my code:
googleMap.addMarker(new MarkerOptions()
.position(pickup)
.title(job.getPickupAddress()));
googleMap.addMarker(new MarkerOptions()
.position(destination)
.title(job.getDestinationAddress())
.icon(BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_BLUE)));
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngBounds(new LatLngBounds.Builder().include(pickup).include(destination).build(), 0);
googleMap.moveCamera(cameraUpdate);
String pickupLatLng = job.getPickupLatLong().latitude + "," + job.getPickupLatLong().longitude;
String destinationLatLng = job.getDestinationLatLong().latitude + "," + job.getDestinationLatLong().longitude;
plotPolyLines(pickupLatLng, destinationLatLng);
Output:
Setting a zoom with latlng bounds is not an effective solution for all use cases.
Might be a related Bug Maps Lite mode with incorrect zoom level first time app starts
Try few solutions / hacks listed here : https://issuetracker.google.com/issues/36218443
Like refreshing the map by destroying and recreating
Also check if by using a single marker with bounds builder if the map sets to the proper zoom level
One last thing make sure that zoom level limits have not been applied.
try changing the line
googleMap.moveCamera(cameraUpdate);
to
googleMap.moveCamera( CameraUpdateFactory.newLatLngZoom(new LatLng(xxxx,xxxx) , 14.0f) );
as suggested in How do I set default location and Zoom level for google map api v2?
or use
map.animateCamera(CameraUpdateFactory.zoomTo(15), 2000, null);
That should move the camera closer to your marker.

Differentiate two markers at same place in android

Here in the code am displaying markers but if many markers have same latitude and logitude then the icons generated must have different colors or it must be moved a little bit so that we must be able to find that its in that location. Is it possible to do?
private void drawMarker(LatLng point, TextView icTag) {
Bitmap icBitmap = null;
icGen.setStyle(IconGenerator.STYLE_ORANGE);
icGen.setContentRotation(0);
icGen.setContentPadding(10,10,10,10);
tvImage.setTypeface(imageFont);
icGen.setContentView(tvImage);
icBitmap = icGen.makeIcon();
MarkerOptions markerOptions = new MarkerOptions()
.position(latlng)
.snippet("" + snip).position(point)
.icon(BitmapDescriptorFactory
.fromBitmap(icBitmap));
marker = googleMap.addMarker(markerOptions);
}
you can setup a bit of logic in your code so that older items are either bigger or with different colors or with different anchors.
Of course you need to check the distance of points before doing that, and i would suggest to use clustering which works fine for this kind of tasks

Google Maps CameraUpdate moves to the wrong coordinates

I am writing an app that uses Google Maps Android API V2. The app will center on a specific latitude and longitude (this position is hard coded to 36.5323, -87.3546) when the user turns on the map and get the user's position every 15 seconds. However, when the user first turns the camera on it centers to (8.407168163601076,-87.35459994524717).
This only happens when the user first turns the map on. If the map is turned off and then turned back on, it centers on the correct coordinates. This has only happened on a Nexus 9. I have two other devices for testing where it properly centers the map on the first try.
This is the code I call to center the map:
LatLng pos = new LatLng(36.5323, -87.3546);
CameraUpdate center = CameraUpdateFactory.newLatLng(pos);
CameraUpdate zoom = CameraUpdateFactory.zoomTo(14);
map.moveCamera(center);
map.animateCamera(zoom);
Can anyone tell me why this is happening?
try this
LatLng pos= new LatLng(LATITUDE, LONGITUDE);
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(latLng, 16);
map.animateCamera(cameraUpdate);

Android Google Maps Util Icon not Centered

I am using the Utils library to add some custom markers in the map. My code is pretty simple, just a copy from the library own example:
......
IconGenerator iconFactory = new IconGenerator(getActivity());
addIcon(iconFactory, text, location, map);
private void addIcon(IconGenerator iconFactory, String text, LatLng position, GoogleMap map) {
MarkerOptions markerOptions = new MarkerOptions().
icon(BitmapDescriptorFactory.fromBitmap(iconFactory.makeIcon(text))).
position(position).
anchor(iconFactory.getAnchorU(), iconFactory.getAnchorV());
map.addMarker(markerOptions);
}
But my markers have their center shifted to the right. I send a big string to text and this became clear (the arrows point how the left and right are not the same length):
I am using all that came with the library, so this is not my 9patch. How can I solve this?
(I am running it in an Android 4.0.3 tablet)
EDIT:
Ok, I tried this same code in an AVD running kitkat on a nexus 5, and the marker appears to be just fine:
Any clues if this is just a problem with 4.0.3?

Want to create google map navigation in my application - custom way

I have created an application in which I am trying to show user's movement by animating marker position.
Using Google map V2.
Location updates using location client.
Animating marker using new location.
But comparing with Google map navigation, there is no continuity in rendering navigation.
Can anyone suggest a better approach? Thanks!
For continuity, I think you need to fetch regular location updates from location client by giving location request like this.
LocationRequest request = LocationRequest.create()
.setInterval(0).setFastestInterval(0)
.setSmallestDisplacement(0)
.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
Then for smooth animation you can follow the approach Steve Benett mentioned. here
The last case you mentioned in the comment about the path. I also had the same issue in one of my app. I tried with gps route simulator app to mock a route. then comparing my app and google map, googlemap followed the correct road path while my app's marker was moving slightly shifted from road. Then I tried some tweaks with marker. Like this
mPositionMarker = mMap.addMarker(new MarkerOptions()
.flat(true)
.icon(BitmapDescriptorFactory
.fromResource(R.drawable.positionIndicator))
.anchor(0.5f, 0.5f)
.position(
new LatLng(location.getLatitude(), location
.getLongitude())));
This worked for me. This positioned my marker on same location as of google map. (Depends on the accuracy of location though).
Thanks for the answer here

Categories

Resources