Background / Concept: I want to create an application that can help user searching for specific things. Let say nearby restaurants. Here I want to include an offline map covering 1 km area around that restaurant, (its easy i can take snap of google map).
Problem: is it possible to indicate current user position on that static image file? I have some idea that I note the Lat / Long of all four corners of that image, take user current position, do some calculation and show the current spot.. But I m not sure where to start and if there is already a good optimized solution.
If I can show current user direction (heading) it will be awesome!
MORE CONCISE QUESTION:
I have a jpeg image (which is actually a street map) and I know lat / long of all four corners of image. How can i show current user location on that image?
P.S. The application is suppose to work without data connection, so I can't load google map etc
Lets say that user position is uLat and uLon, and the map have top left corner tlLat and tlLon, and bottom right corner brLat and brLon. Finally, map size is x and y pixels.
userX = x*(uLon-tlLon)/(brLon-tlLon);
userY = y-y*(uLat-brLat)/(tlLat-brLat);
This is an aproximation that only works for small distances (1 km should be fine) as it's not taking into consideration the earth curvature.
I'm not sure that's legal to use google map screenshot without authorization.
good luck.
Related
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.
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.
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.
I am trying to create a prototype that could guide a person to his destination place.
place is a wide building with several floors.
i can obtain/retrieve the maps (still images). e.g. current:1F destination:5F; so I can get the still images of 1st,2nd...5th floors (5 image files).
Scenario:
start the application
input the current location (or may automatically set using current location) & destination
click the search route button to search the maps to use (still images) & mark the current location & destination
update the current location upon moving/going to destination
Problem:
I just need to display 1 image file (each floor) at a time then move to other floor by using scroll bar. But.. don't know how to display it.
I can get the current location coordinate via WiFi but don't know how to put it into still image to mark the current location.
For sure there is already look a like sample application available.
Could you share the concepts/ideas or would you include the code snippets. Big Help with my thesis.
Any guidance on the right direction is appreciated.
You have a couple possibilities, create your own MapView like object to provide scrolling ot overlay your map on the Google Api. Example usage of the MapView Api is available through the Location dev guide.
To do this via your own View will be easier if you understand basic graphics programming and transformations for zoom and pan. (If you're good at math it will be no trouble to learn). Use an ImageView with android:scaleType="matrix" override the MotionEvent handler to get the touches then process them into a tranlation and zoom matrix.
To associate the indicator to the image make two pixels into anchor points that coorespond to a real life lat/long. Usually its (0,0) and (width,height) of a rectangular image. Make your life easier and make sure the images are to scale. Then using a second ImageView (for the indicator) draw it on top and move it to the correct place on the screen and make sure the background in this View is transparent as well as the background of your indicator or you'll have a rectangular block "halo".
Be sure to check the accuracies of each location given by the LocationManager.
Additional Content
onCurrentPosition(Location current){
double hypotenuse = upperLeft.distanceTo(current);
double bearing = upperLeft.bearingTo(current);
double currentDistanceX = Math.cos(bearing) * hypotenuse;
// "percentage to mark the position"
double currentPixelX = (currentDistanceX / upperLeft.distanceTo(lowerRight) * Math.cos(upperLeft.bearingTo(lowerRight))) * mapWidth;
moveIndicatorX(currentPixelX);
}
Using Google Maps on Android does anyone have any ideas on how to load only markers that would be displayed on the current screen?
I'm thinking about sending a request to a web service that returns the lat/lng for the relevant markers. But what would the parameters be that I could use to calculate if a given lat/lng is within the screen?
What would be perfect would be something like Gowalla's implementation
Any ideas?
Mike
I'm working on an app that needs to do some similar things, here is my suggestion (my app is SDK Level 7)
In my example below, mapView is an object of type MapView
mapView.getLatitudeSpan();
Returns:
The current latitude span (from the top edge to the bottom edge of the map) in decimal degrees multiplied by one million.
and
mapView.getLongitudeSpan();
Returns:
The current longitude span (from the left edge to the right edge of the map) in decimal degrees multiplied by one million.
Here are another three helpful methods.
mapView.getLocationInWindow(location);
mapView.getLocationOnScreen(location);
mapView.getZoomLevel();