Using hand drawn map in android application - android

In my android application I want to use "handmade" maps. It's an artistic map image, based on a real map, so it's geographically accurate. The map cover a relatively small, walkable area (like a neighborhood in a city). The map is bigger than the screen size, so the user will drag the map (but always at the same scale, so no zooming). The application has to work offline, with no Internet connection, but I want to show the user's current (possibly moving) GPS position on this map. Is there any way to do this?

Yes this is possible, and in your case not so difficult.
Measure 3 reference point;
1. near or at left upper corner (NW)
2. near or at right upper corner (NE)
3. near or lef middle or right lower corner (S).
next step is to map the 3 points to pixel and screen coordinates.
Then you need to do an linear interpolation for latitude (between y/lat coordinate of Point 1 and 3)
And an separate linear interpolation between Point1 and 2 for longitude /x value of your GPS coordinate.
With this knowledge, you search further and read some poste here, etc.

You may want to look into OpenStreetMap for your mapping. It allows you to specify a custom tile source for the map. Here is a related SO question.
You will need to break your image up into pieces, this site gives a good explanation on how the tiles are formatted.

Related

How to display location in a custom indoor map, given the coordinates X,Y

I want to create a map for an indoor location finding App. I have images of the building layouts and how they should look, but I don't know how to show the exact location given some coordinates (X,Y). I only need something simple.
I'm creating an indoor location finding app, based on WiFi signals. The algorithm part returns a pair of coordinates (X,Y), and I want to display the location somehow.
I really don't know how I should do this.
My first thoughts were to get the pixel coordinates of the (0,0) point on the image, and the distance in pixels between two points, i.e (0,0) and (0,1), (I know they are equidistant). The image, the pixel coordinates and distance are stored in an object.
Now, given a pair (X,Y) the object above, I can calculate on which pixel the location should fall on. But this isn't MATLAB, and I'm not sure how to edit it or if I can add a Pin or something on top of the image in order to show the location.
Example:
Here is an image of a building
I know for the point (0,0)(starting from bottom left) pixel coords are (47,223) and the distance between the points is 45px.
Given the coordinates (1,2.5), I have to show the estimated location. Which is the pixel (92,110) and have to highlight it somehow.
This is my only idea, as I'm pretty new to Android developement. It doesn't necessarily have to be like this, I just want to pinpoint a location given a pair of coords (X,Y). I'm open to suggestions.
Thank you for your time.

Position infoWindow away from overlapping polyline

I'm developing an Android application which contains an activity with google maps where I plot a path between two location with polylines. I have added markers at source and destination with infowindow showing some data, but these infowindow blocks the polyline and makes user zoom the map to see the path. Is there a way to move infowindow similar to how Uber does?
Any help will be appreciated.
Thank you.
There are really two parts to this problem: (1) establishing where you want the info window and (2) how to get it there. I will be focusing mostly on (1) and try to help with references for (2).
(Note also there is a third problem which can be inferred from the animated gif: the infowindow for "Home" is adjusted because it is clipped in the final view - I've added an approach to this at the end.)
One approach to (1) is to create a bounding rectangle around the path from Point A to Point B. This is a simplification of the problem which has shortcomings to be shown but is a good initial approach. There are optimizations which I think you'll soon realize to better fit the location in extreme cases.
Use this bounding rectangle (R) to determine the minimum dimension relative to the marker anchor of interest (d1 vs d2).
Using the mininimum dimension you can then compute a screen distance from anchor to nearest side of info window (f). From this nearest point you can then determine the anchor offset of the info window.
First some pictures which serve several purposes: (a) identify key locations by label and (b) to start considering more complex problems:
The simplest case is pictured here...:
...but the the labels are bit crammed so a second looser case is pictured here:
Determining the bounding rectangle is straight forward albeit inefficient. Loop over the points of the path (from My Location to Home) and maintain the maximums and minimums of latitude and longitude (note that the -180 to 180 longitude crossover is a pervasive complexity not addressed here - just keep it in mind). This yields:
LatLng upperLeft (maxLat, minLng)
LatLng lowerRight (minLat, maxLng)
So establishing the location of the info window of A is then:
Compute the length (in meters) from A to side of rectangle by using Point A to (A lat, M lng) and Point A to (M lat, A Lng). (Use `SphericalUtil.distanceBetween`)
Determine the lesser of the two measurements, L.
Use L (distance in meters) to compute a screen pixel equivalent S.
Adjust S to offset from edge of BR (Sadj)
Use Sadj (in screen pixels) to compute the Info Window offset (in screen pixels) taking into account the Info Window anchor point and the dimension of the Info Window.
Set the info window anchor (which is relative to the marker coordinate system) and render.
Optimization: Let's say you prefer the location of 'Home' in the 2nd picture to be something like:
Then the optimization would be to consider a smaller bounding rectangle using only some subset of the closer segments of path. So this leads to the next problem of determining when to optimize using thresholds for d1/d2. This same optimization would be used when the zoom level does not include both points; just use the points on screen to compute the bounding rectangle.
For the third problem where "Home" is clipped after the zoom is to account for the dimensions of the infowindow when applying the bounding rectangle - this way the minimum dimension will always include the corresponding extent of the info window.

Android Google map with inset overview when zoomed in

I am developing an android application using Google maps with clustering of markers. The application works fine however once you zoom into a specific area and all the clusters expand to individual markers I would like to also show a small view that represents the entire map, where you are, and where all the markers are, to enable the user to navigate round the map while zoomed in. Ive Googled and searched SO, but not found anything. Is there any "off the shelf" solution? Or am I going to have to code this all myself? The type of solution I am looking for is the type of small window that many games use to show an overview of where the player is and all the points of interest are within the current level.
I haven't seen any "off the shelf" solutions, but here is what I would do here:
1) Create an additional fragment of the map. Place it in one of corners like games do
2) Here is where all the magic should happen. You need to synchronize these 2 maps. Map's Projection lets you to translate geo coordinates into XY coordinates within the view. That's being said you can get lat/lng of your top-left and bottom-right corners on the main map and translate these 2 corners into top-left and bottom-right XY coordinates of the mini-map's view. Now, when you have XY coordinates, the only thing you need to do - is to draw a rect on top of the mini map.
There is even easier and more native solution - since you have top-left and bottom-right lat/lng coordinates - you can draw a set of polylines on a minimap to get a rect. But in this case it will be hard to move it around (with your finger) in case you want to change current main map location using mini-map

Android google maps zoom to fit mark and current position

I'm trying to create a custom "my location" button for my app using Google Maps.
What I'm trying to do is to center the map around the location of the user, which is already done and working flawlessly, but also want to zoom in just enough to see a marker of my choice (this is actually the closest of a set of markers I have in memory, but that's not important now).
I haven't been able to find how the zoom variable works here. If I know the marker I want to show is 0.5 GPS units away from me, how can I center the map around me in a way that includes that marker on its boundaries? I'd also use a padding to make sure it perfectly fits in the map.
LatLng my_coordinates = ...;
LatLng closest_mark = ...;
map.animateCamera(CameraUpdateFactory.newLatLng(my_coordinates));
So now I want to modify that code to not only center the position to my_coordinates but also make sure zoom will make closest_mark fit in the viewport
CameraUpdateFactory.newLatLngBounds( ?? , /*padding*/);
I don't think there is a specific zoom variable in the api you can control along with the points in the map. (And LatLngBounds just takes in the upper right and lower left bounds and gets you a view accordingly).
I believe what you could do is with a little geometry. If your marker is very close to your location (you can consider it a rectangle), get the distance between the two and extrapolate that on the opposite direction with the same distance (multiple by a small factor if you want some padding) to get the other coordinates, and then you can get the upper right and lower left coordinates (simple geometry).
If your marker is quite far and the surface of the earth comes into picture, you may have to use the haversine formula (great circle distance).
Hope this helps.

Determining where to animate the map given a list of GeoPoints

My android application loads some markers on an overlay onto a MapView.
The markers are placed based on a dynamic list of GeoPoints.
I want to move the map center and zoom into the area with most items.
Naively, I can calculate the superposition of all the points, but I would like to remove the points that are very far from the mass of points from the calculation.
Is there a known way to calculate this ? (e.g. probability, statistics .. ?)
I once solved the exact same problem you describe for a real estate app I wrote a little while ago. What worked for me was:
Calculate a center point somehow
(centroid, average the lats and
lons, or whatever)
Calc the distances between this imaginary point and each of your real pins
Use a Standard Deviation algorithm and remove any pin whose distance has a StdDev >
2 (or whatever threshold for you)
Repeat steps 1 - 3 (you'll be using a new center point each time
you loop) until there are no more
outliers to remove at step 3
This approach work great for my needs. But I'm sure there's more interesting ways to solve the same problem if you look around. For example, I found this interesting CompSci paper...
http://people.scs.carleton.ca/~michiel/outliers.pdf
Good luck!

Categories

Resources