How to get the pixel size of the full map? - android

I have partial map of the world (like America or Africa). and I need to know to pixel size of the world map based on the size of the partial/cropped map pixel size.
I have the size in pixel of the partial map (like 480x256), and I have the minLongitude,maxlongitude,minlatitude,maxlatitude (aka left,right,top,bottom edge)
I know that longitude is easy because linear :
FULL_CIRCLE_DEG = 360
longitudeDelta = (maxLongitude-minLongitude)/FULL_CIRCLE_DEG
MapFullSize = mapCroppedWidth/longitudeDelta
But for the latitude, it's kind of different:
FULL_LATITUDE_DEG = MAX_LAT_ON_EARTH - MIN_LAT_ON_EARTH (like 85.7543...-(-85.7543...))
latitudeDelta = (maxLatitude-minLatitude)/FULL_LATITUDE_DEG
MapFullHeight = ????
Please someone can help me ?
I find lot of algorithm to get a GPScoordinateToPixel conversion but nothing on square calculation.
Thank you.

Here's an idea. First work out the area of your rectangle which is specified by minLongitude,maxlongitude,minlatitude,maxlatitude. Then the ratio of your current map area to the area of the whole world map could be used to scale up the current number of pixels that the map currently occupies to the number of pixels that would be required for the whole map.
To work out the area that the map currently occupies, I think you need a bit of spherical trigonometry, and you can find what you need here on wikipedia. That page on wikipedia gives you a formula for the area of a spherical triangle, so if you regard your rectangle as two triangles, you can use that formula and calculate the area of the current map.

Related

Using hand drawn map in android application

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.

How can i set zoom level according to height from ground level (eg.1KM) in google map in android?

I am working with Google API and I want to show view of any location on Google map from particular height. I don't want to assign zoom level directly. I want to calculate it dynamically with respect to height (Eg. 1Km, 2Km, 3Km, etc.). If any one have idea please let me know.
Thanks in advance.
Try using map.setZoom(your value)
function addMarker(lat, lng, info) {
var pt = new google.maps.LatLng(lat, lng);
map.setCenter(pt);
map.setZoom(your desired zoom);
}
Referred: https://developers.google.com/maps/documentation/javascript/reference#Map
You won't find a direct, out-of-the-box solution for your problem because it depends on the size of the device and the distance from which you look at it.
For example, if you are holding you device at 40 centimeters from your eyes, and then you move it to 50 centimeters, the perceived distance to the ground will change a lot.
Anyway, you can estimate the distance using a formula to Calculate distance knowing actual and perceived size.
Using this formula you can calculate the perceived distance for each zoom level based on the perceived size of an object with a known size (a car or a building for example), the size of your device and the distance from which you're looking at it, and then find a relation to know what zoom level you need to apply to simulate a given altitude.
Take into account that this will always be an approximation because you can't be sure about the distance from which your users are looking at your map, and also because the map represents the earth in a plane, so the farther the zoom, the worse this method will be.

Calculate polygon area using Polylines

I need to calculate a polygon area on my mapView. I studied this case, and de Polylines shows the best way to make a area, with the points that the user was informed. But I didn't find the way to calculate his area! Can anyone help me please? Or suggest other alternative to draw polygons and calculate area/perimeter in android application.
convert lat/lon points to cartesian space
Use area of polygon formula you easily find in wiki.
ad 1) if polygons diameter are not more than some 10s of kilomters an EquiRectangular Projection makes sense and is very simple, using the center of the polygon as center of transofrmation (cos (centerLatitude)).
Otherwise task 1 is complex.

Influence the Tile size in Android Maps TileProvider?

I have been playing around with the TileOverlay in Android Maps v2 and I have built a custom TileProvider very very similar to this one
But there is something that strikes me as odd. No matter which number I pass on to the Tile constructor, the image on the screen is always the same - 4 to 9 Tiles sharing the screen space evenly, like this:
Of course this is something you would expect from reading the documentation:
The coordinates of the tiles are measured from the top left (northwest) corner of the map. At zoom level N, the x values of the tile coordinates range from 0 to 2N - 1 and increase from west to east and the y values range from 0 to 2N - 1 and increase from north to south.
But you might guess that there is in fact such a functionality from looking at the Constructors documentation
Constructs a Tile. Parameters
width the width of the image in pixels
height the height of the image in pixels
data A byte array containing the image data. The image will be created from this data by calling decodeByteArray(byte[], int, int).
So obviously I misunderstood something here. My personal guess is that the tiles have to cover an entire "Map Tile" and can therefore not be shrunken
My goal would be to make my tiles about 10dp of the screen. Therefore again my question to you:
Can I realize this with TileOverlay or will I end up using custom Markers?
The size of the tile specified in the constructor is the size of (every) bitmap tile you are supplying to the map. This allows you to provide tiles at different densities for different screens if you have such resources.
It will not change the size of the image that is drawn on the map. The physical size of a map tile is defined by the zoom level, where a zoom level of 0 is a single tile covering the entire world, 1 is 2x2 tiles, etc. This is part of an open web map standard for map tiles, not defined by Google.
API docs:
https://developers.google.com/maps/documentation/android/tileoverlay
Ref:
http://www.maptiler.org/google-maps-coordinates-tile-bounds-projection/

Take all screen coordinates

Assume that my current point is lat = 50.000 and long = 50.000 and I want to show some bus stations on these location but my limit should depends on zoom level.
So far, for that aim I find a way: If a can take left-up corner and right-down corners lat's long's ; I will find stations between these locations.
Do you know how can I take these points or any different idea about this situation?
Thanks in advance..
Well you can easily get the top left and bottom right lat/lon coordinates using
GeoPoint tlGpt; // Top left
GeoPoint brGpt; // Bottom right
tlGpt = mapView.getProjection().fromPixels(0, 0);
brGpt = mapView.getProjection().fromPixels(mapView.getWidth(), mapView.getHeight());
At any zoom level where you could actually see the bus stations on the map, then the top left longitude could be considered the same as the bottom left longitude, similarly bottom left long would be approx = bottom right long. Thus you could consider the bounding box as a rectangle, rather than an isosceles trapezium (trapezoid in US English)
If you just want a rough measure to pick up a reasonable sample of objects, then lat/long "distance" is good enough. Just make sure you divide the latitude range by the cosine of the latitude, to get the longitude range (i.e., ∆long = ∆lat/cos(lat)). This is to compensate for the contraction of longitude lines as you approach the poles. You use ∆lat as the basis because latitude lines have the same distance between them everywhere on the globe.
For a more accurate measure, there are some complicated functions that allow you to compute great circle distances from lat/long pairs, but it is conceptually much easier to convert lat/long pairs into 3-D coordinates, and use a simple pythagorean distance to approximate the great circle distance. You could use 2*r*acos(d/(2*r)) (if my whiteboard geometry serves me well), where r is the nominal radius of the earth, to get the exact great circle. But if all you want is to get objects within a range, you can invert the formula to get the pythagorean-distance equivalent of the great-circle limit. This can also be used to derive a 3-D bounding box to speed up the search. If your database supports R-trees, then you're laughing! SQLite supports R*Trees, but they are disabled in the default build, so I don't know if they're available on Android (it seems that it isn't).

Categories

Resources