Reputation: 25
I am using the code below to draw a bunch of vertical lines at 5 degree intervals on a Google map (android API v2). All works great until zooming out to approximately zoom level 5.1, at which point all my lines disappear. Is this a bug in my code, or something that the maps API does on purpose? How can I get these lines to show up at all zoom scales?
Thanks very much.
if (gMap != null) {
double lat = loc_service.getLatitude();
double lng = loc_service.getLongitude();
LatLngBounds bounds = new LatLngBounds(new LatLng(lat-(MAP_WIDTH/2), lng-(MAP_WIDTH/2)), new LatLng(lat+(MAP_WIDTH/2), lng+(MAP_WIDTH/2)));
CameraUpdate cu = CameraUpdateFactory.newLatLngBounds(bounds, 720, 720, 0);
gMap.setMyLocationEnabled(true);
gMap.moveCamera(cu);
// initialize the time marker AT ONE MINUTE INTERVALS
time_markers = new ArrayList<Polyline>();
// calculate distance to zero-second mark
double offset = getLngOffset();
for (int i=-MARK_RNG; i<MARK_RNG; i++) {
PolylineOptions plOptions = new PolylineOptions()
.add(new LatLng(90, (lng-offset + (i*5))))
.add(new LatLng(-90, (lng-offset + (i*5))))
.width(2)
.color(Color.BLUE);
time_markers.add(gMap.addPolyline(plOptions));
}
}
Upvotes: 1
Views: 1507
Reputation: 22232
This seems like a bug in the Google Play Services library similar to the one I reported some time ago.
I just tried
map.addPolyline(new PolylineOptions()
.add(new LatLng(90, 5))
.add(new LatLng(-90, 5))
.width(2)
.color(Color.BLUE));
and it draws a line from 0,0
to 0,5
on low zoom levels and from 0,5
to 90,5
after you zoom in. Both are of course incorrect.
A workaround would be to use 85
instead
map.addPolyline(new PolylineOptions()
.add(new LatLng(85, 5))
.add(new LatLng(-85, 5))
.width(2)
.color(Color.BLUE));
but don't ask me why it works correctly this way...
You may also want to add more info to the linked issue report.
Upvotes: 1