Get actual image coordinates of image in Android webview onTouch event - android

I'm loading floor plans into an Android application. I need the user to be able to identify problem areas on the floor plan with a single click. My thought process is to identify the click action, reload the html of the webview adding my marker asset to it at the specified location.
I've loaded the image into a webview to take advantage of zoom capabilities. I can get the X,Y coordinates of the webview where the click occurred, but I can't figure out how to get the current zoom level. Also, I'm not sure what math will be required to translate the X,Y,scale to actual pixel coordinates.
Is the webview the right view for me to use?
EDIT:
Using the link suggested below, I got the zoom functionality working. I still can't figure out how to place a drawable marker on top of the TouchImageView, much less get the coordinates that were actually touched on the image.

For your zoom question as well as coor, How can I get zoom functionality for images? should help you
The accepted answer does use a WebView, but the other answer uses a better approach for enabling zoom. It also provides the necessary math required for translating your X and Y coordinates into usable points.

Related

Android - Get touch point coordinates relative to zoomed image

I'm looking for the best way(s) of getting the position of a point I touched on an image and get it's coordinates relative to the image size.
For example, I get, as the parent image, the map of a building floor. And the user need to be able to zoom in and point on the map a point that will be registered in a database in order to be retreived later.
I never really had to work with images and canvases on Android so I'm a bit confused. What might be the best approach. I already found a lot of document but couldn't find one that would fit the idea I need to develop.
Thanks in advance for you help,
Matthieu

Build my own map and interact with it with zoom and clickable areas

I need to build a screen with map of a theater, and user can interact with zoom in/out and choose seats on map.
When user touch on a seat, the icon of seat is changed.
Is there some lib/component to build my own map with touch areas? Or some good idea to use Android API to solve this problem?
Thanks.
You should take a look at the SurfaceView API.
It provides you with an easy to use abstraction for drawing on a canvas. You can use it to render your theater image and intercept touch events on it. However, zoom in and zoom out are not supported out of the box, so you should implement them separately.
Another thing you can do is show your image in an ImageView and use scaling to implement the zoom in/zoom out, but then intercepting the exact touch position can get a little tricky.

Image Zoom, Pan and Sliced images

I have a image received from server. I have to provide Zoom and Pan functionality to it.
I also receive set of point of image, when clicked on these point of image i need to show a pop up.
Initially i thought of using default viewer for image but the pop up of click of specific point is out of question.
I cannot slice the image also
Point me to proper direction.
I think this library fulfills your requirements: https://github.com/chrisbanes/PhotoView

Pinch-To-Zoom feature for TiledScrollView

I used https://github.com/ened/Android-Tiling-ScrollView library to display large tiled image. Everything is working fine. Only problem is that, I want to zoom only particular part which I touched(pinch-to-zoom as in Google map). Now, its always display tiles from beginning for all zoom levels irrespective of where I touched. Sometimes, it takes me near where I want to zoom but its not perfect as sometimes it takes me to different part. Following code does moving logic
mScroller.startScroll(getScrollX(), getScrollY(), newOffsetX, newOffsetY);
First 2 parameters indicate start scroll offset and last 2 indicates destination points to where scroll ends. I tried different combinations for last 2 parameters but ran out of luck.
If it's a ImageView, I would have done
canvas.translate(x, y);
to Zoom particular part but unfortunately its not ImageView. Even though I applied ImageView zoom logic as in https://github.com/jasonpolites/gesture-imageview to tile Zoom but had no luck.
Suggestions or clues are greatly appreciated.
Thanks.
Got a very nice library for custom mapView with almost all the features of google map. Its here.

Android custom GPS map application

I want to build an app that uses GPS data and a building map I provide to show the user where in the building on the map they are. This will be done in a specific building that i already know gets GPS and cell service.
At first I thought the easiest way to do this was to see if I could use Google maps to plot the users location and then just "overlay" my custom building map on top of the Google map so that I wouldnt have to deal with any of the gps information or the complexities of the mapping I would just have to scale my "overlay" to fit properly on top of the Google map so that the user was shown in the correct room in a building. I'm wondering if anyone can provide me any information on how to do this or if there is an easier way to accomplish my map. Any information at all is helpful!
You want...
Google Map View
...and more specifically you will probably want to read the subsection appropriately titled: "Part 2: Adding Overlay Items"
EDIT: Whoops! Nevermind! I misread your question... that is only if you want to overlay an item on the map. Sorry...
There is no possibility to use closer zoom level than that you can see on standard GMap i.e. in browser. Other problem is that google uses GeoPoint class based on cardinal microdegrees to draw overlays, and it's accuracy is to low.
You can look on jGarminImg - it's java library - unfortunately written for using with swing, but it should be relatively easy to make it work with android. On the other hand - you have to make your own map.
You can use standard overlays, or you can make your map in kml format and use this example to display it.
You may be able to achieve this with a custom view that displays your building plan and knows the precise co-ordinates of each corner of the building.
When you receive your location updates you can add a marker to your custom view by translating the real world position into a position in the image using something along the lines of:
pseudocode:
markerX = realWorldX - mapStartX;
markerY = realWorldY - mapStartY;
if( isOnMap( markerX, markerY ) )
{
drawMarker( markerX, markerY );
}
Yes you can overlay bitmap images on top of the Google MapView.
All you have to do is subclass the Overlay class, override the draw method, and draw on the canvas. You have to provide a rectangle of GeoPoints (probably the top left and the bottom right corners) to anchor the building bitmap on top of the MapView. You use mapView.getProjection() to translate the latitude and longitude into xy coordinates on the canvas.
I assume drawBitmap(Bitmap bitmap, Rect src, RectF dst, Paint paint) will be useful here. Bear in mind that src and paint can be null. If the GeoPoints you used are accurate, the bitmap will adjust automatically to pans and zooms, although it might get pixelated if the user zooms in too much.
edit: I am not so confident that Google Maps will have your building stays at the exact same GeoPoints in different zoom levels, so you might have to adjust those values for different zoom levels
If you need only the map of the building, it should not be too difficult to plot the location on an image without using Google Maps, provided that you can determine your location as coordinates inside the building.
You need to know two coordinates: north-west and south-east corners of the building map you are using. When you get GPS location updates, the correct location on the map image can be easily calculated based on these corner coordinates.
I would do it like this,
Place a marker on the google map to indicate the position of the building
Drilling down on the building would load your building map as a custom view. Plot the user location on the custom view
I think trying to overlay your building map on a google map while possible will be more complex to code than doing it via a custom view.
Also overlaying the lowest zoom level with your building map is not going to give you enough resolution unless you have a thumping big building. Whole blocks are pretty small
One issue you have probably already considered is the device will revert to cell tower and wifi for it's location when inside the building giving you a less accurate location fix.

Categories

Resources