Trying to make an google maps overlay in an android program. Inside of my overlay's draw method, I have two ways of adding a pin. One of them works, and one does not. Unfortunately, the one that does not work is also the only one that has the ability to add a shadow! Any help?
#Override
public void draw(android.graphics.Canvas canvas, MapView mapView,
boolean shadow) {
Point po = mapView.getProjection().toPixels(mapView.getMapCenter(),
null);
// This does _not_ work, but I would really like it to!
drawAt(canvas, mapView.getResources().getDrawable(R.drawable.map_marker_v),
po.x, po.y, false);
// This does work, but only does half the job
canvas.drawBitmap(BitmapFactory.decodeResource(mapView.getResources(),
R.drawable.map_marker_v), po.x, po.y, null);
}
Edit: fixed type
I think your problem may simply be that you haven't set the bounds on the drawable in drawAt(). You can either manually set the bounds using Drawable.setBounds(), or you can use ItemizedOverlay's convenience methods boundCenter() or boundCenterBottom().
I believe the reason the second method works is because with a decoded Bitmap you don't have to specify the bounds of the Drawable.
At first sight, nothing stands out to me as to what could be causing your pin to not draw. But, I might have found a temporarily solution.
Looking on google lead me to this post where an user posts their version of an Overlay with the ability to add an icon along with a shadow. It might be what your looking for.
Hope this helps.
Related
On Android API 11 there is method View.getMatrix. however there is no shuch method for android API 8. How can I provide simmilar functionality?
gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
public void onItemSelected(AdapterView<?> parent, View v,
int position, long id) {
geg = 90;
// shift=v.getMatrix();
current = (ImageView) v;
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
}
});
In galleryview i can drag image across and behind screen, but after zooming image can appear so afar avay from screen so you do not know where to drag it back. So i want to make buttom to set it to original possition.
This method in API 11 gets a field TransformationInfo mTransformationInfo; in View: see here. Sadly, in API 8, it's not just a matter of the getters not being available, the field simply isn't used.
So there is no implementation possibility.
But you probably didn't want to do that anyway:
You're not really meant to use the api like this. Modifying by calling getMatrix() would circumvent a whole lotta calls that need to be made. Look at the source for setPivotX(float pivotX) for example. Use these accessory calls. They're you're friend! Don't think- I've got a view that's like this, how do I apply the inverse transformation to it to go back to where I was. Do think, after this transformation, I'm going to set an identity matrix on everything so that the view isn't transformed. Then you don't need to do any work!
Most Android views have their own matrices that are concatenated onto the Canvas in an overriden Draw call. So trying to get hold of something in View isn't going to help you. Say, for example, you wanted to reset the cropping on an ImageView. Well, getMatrix() of View simply won't tell you anything about that transform.
Why do you want to do this? What's the background here? Are you wanting to reset an animation? In that case, you're interested in the layout properties, not the transformations performed on the canvas!
By all means edit your question to include these considerations, and then it'd be lovely to come to a wider solution.
If a user does a "pinch zoom" on the map, my overlays don't properly size until the end. This has been noted in other posts, so i assume it is a known issue.
Problem is, my client finds it totally unacceptable, as I am tasked with making the android app look as good as the iphone version.
Is there any way to correct this, even if it is a horrible hack? For instance, can I subclass the mapview and handle drawing or override some other method?
The common solution is to not draw overlay during zoom animation.
UPDATED:
Sorry, I've confused zoom and move.
The problem with zoom is that you can't rely on zoom level. Instead you need to draw your overlay based on MapView.getProjection().
All,
I have a need to display information on a MapView object. No problems there.
The issue is that there are times when the MapView object displays map details that visually compete with my overlay data.
So, what I'd like to do is provide a way to "scale back" the MapView object visually by using an alpha channel.
Can an alpha value get applied to a MapView object? If so, how?
Alternatively, I was thinking that perhaps a separate all black overlay might provide the same results. Scale the alpha of this overlay and I might end up with the same overall effect.
Insight please.
Thanks.
Rich
Are you sure you want to do this? It might be better to revisit your overlay's graphic design... simply giving them a thicker border might be a cheap solution to the problem.
First suggestion would be to subclass MapView and override dispatchDraw() with something like this:
#Override protected void dispatchDraw(Canvas canvas) {
// Firstly let MapView draw
super.dispatchDraw(canvas);
// Draw a translucent fill on top of it
canvas.drawColor(0x7FFFFFFF);
// TODO: Draw my overlay
}
I am developing an Android mapping application and I have managed to work Google's ItemizedOverlay tutorial into my code. I'm plotting my little circle on the map nicely.
However, I would like to label my tiny symbol with its title -- all the time. I'm going to be dropping a few different symbols on my map and the able to display their labels would be a BIG help. I got the onTap method working, but when you tap the screen, it takes over the whole display -- which is not very helpful.
I haven't managed to find a thing about this on the internet, so I'm not optimistic, but if anybody's got any sort of suggestion, that would be much appreciated.
Not sure what onTap has to do with this or what you mean by "it takes over the whole display," but I think to display labels you'll have to draw them yourself. You could do this in a couple ways. One would be to override the ItemizedOverlay.draw method directly, and iterate through each one of your GeoPoints and draw the title directly onto the Canvas at some small offset to that location. Another possible way would be to return a custom marker; instead of just returning the symbol, you could create a Picture by drawing the circle and then drawing some text next to it, and then you would be able to wrap this in a PictureDrawable and use that as the marker for your overlay item.
My onTap method looks like this:
protected boolean onTap (int index)
{
OverlayItem item = mOverlays.get (index);
AlertDialog.Builder dialog = new AlertDialog.Builder (mContext);
dialog.setTitle (item.getTitle());
dialog.setMessage (item.getSnippet());
dialog.show();
return true;
}
The calling application passes in its context (this) when it instantiates the Itemized Overlay. I'm still not really sure what that means, but I save the passed-in context in mContext, and use it in onTap(). I can't really take credit for it, naturally, since somebody else posted in to the Internet. It does display the Overlay's information on the screen, but (unfortunately for me) not in a manner that I'm happy with.
I'm working on overriding the draw method, but that's been much interrupted and is still in its early stages. I'll post it here if there's any interest.
R.
I'm trying to draw a route onto my MapView.
I've extended Overlay and implemented the draw() method.
The route is displayed properly, although while debugging,
I added a breakpoint on draw(), and noticed it is being called constantly.
I only want it to be re-drawn if someone moves the map or zooms (the draw take into account these changes when drawing the route)
What can cause this ?
There are two draw methods that can be overridden.
void draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow)
Desc: Draw the overlay over the map.
boolean draw(android.graphics.Canvas canvas, MapView mapView, boolean shadow, long when)
Desc: Draw call for animated overlays.
I originally overrided the second one.
After changing to the first method, it worked out.
i think the draw method is called repeatedly because the of the background being redrawn constantly. try setting the "MapView.ReticleDrawMode" to DRAW_RETICLE_UNDER. This basically tells the mapView to draw the reticle under the overlays. So overlay's draw method will not be called when the background is recalled. this fixed the issue for me.
for more info, look here: MapView Api
I got tripped up when I didn't realize that the draw method get's called not only any markers that you draw, BUT also the shadow of those markers. So as an example, if you have two markers and you have shadows set to true (which is the default setting), then you'll have the draw method being called 4 times (once for each marker, once for each shadow of the markers)!
After further review, the Overlay draw() does actually work as described in the documentation. One draw for shadow = true, and one for shadow = false.
The interesting thing is that the specific overlay draw() method responds as advertized for each element drawn in the MapView. For example, in my case, it seems to respond for each the google map, the Google logo drawn on the map, and then the particular overlay I have drawn myself. Obviously twice for each (shadow true|false).
This is probably the intended way to render the maps. I haven't found or spent enough time researching for this information.
Also, in my own case, I have a transparent panel rendered over my map with CheckBox(s) and TextView widgets. The TextView forces the draw() method to run non-stop since the textview is always listening for input and hence triggering the redrawn of the overlay.
In my app, I have an indefinite progress bar (e.g. spinning circle) show when I'm loading network data for the map. When the network data is finished loading, I was setting the progress bar's visibility to invisible. However, this caused the map to continuously redraw as it seems that any animation (I'm guessing) which takes place over the map will cause the map itself to redraw. Simple solution to this is to set the visibility to gone instead. E.g. change this:
ProgressBar loadingIcon = (ProgressBar) findViewById(R.id.loadingIcon);
...
//Network data now finished loading...
loadingIcon.setVisibility(View.INVISIBLE);
to this:
loadingIcon.setVisibility(View.GONE);
which removes it entirely from the map, no longer animates over it and therefore does not cause draw() to be called a indefinitely.
For me it looks like a strange bug - sometimes the draw method is called continously, sometimes not.
see here.
I know this is an old problem, but I just now encountered it. This is a "for what it's worth" post.
The draw loop turned out to be a coding error on my part. According to the doc, if the draw routine returns true, it is asking for an immediate update. If false is returned, only two passes are made for each overlay; one for shadow true and one for shadow false. I was returning true which resulted in a constant update. After I changed to returning false, only two passes per overlay occurred. No loop.
You can simply add this to your ItemizedOverlay class:
#Override public void draw( Canvas c, MapView m, boolean shadow ) { super.draw( c, m, false );}
This will remove the shadow from your mapview overlay.