Domanda

To explain the question from the title. I want to get information such as if user is in the city, forest, how far he is from river/lake/sea (or even in general how far he is from water). It doesn't have to be super precise.

If it's not possible with standard SDK is there any other library that can help me get such info about current location?

È stato utile?

Soluzione

1) Check for Water

You could fudge this with such techniques as making a ReverseGeocodeQuery and checking the country field is filled in the first entry returned and distance to the nearest result, however this would also fail in underpopulated areas. An alternative would be to use the places API and check for the nearest place in the underwater category.

A better technique would be to build your own binary black-and-white minimap based on pixel analysis of map tiles from the Map Tile API. The Map Tile API is based on the normalised mercator projection which means that the whole globe is one square at zoom 0, 2x2 at zoom 1, 4x4 at zoom 2 etc. Therefore if you check the color of the top left corner of a tile (and its blue) you can be certain that the 4 pixels below it at the next zoom level will also be blue. This can be used to define a "water" tile:

Your final map will look something like this:

Ocean

White pixel in mini-map = blue pixel in top right corner of map tile at zoom 10. Each tile is 13 km wide. Use a bigger map and higher zoom level to get more accuracy. Store this on the device.

Now all you need to do is check whether the pixel representing map tile at your input lat/long is black or white. Obviously each pixel here could be encoded as an individual bit and you could use a bit mask so you wouldn't need to take up much memory.

The tiles you would need to analyze are as follows:

http://1.aerial.maps.cit.api.here.com/maptile/2.1/basetile/newest/terrain.day/zoom/column/row/128/png8?app_id=AppID&app_code=AppCode

enter image description here

2) Check for Urban Area

Again you could fudge this with such techniques as making a ReverseGeocodeQuery and checking the city field is filled in the first entry returned and distance to the nearest point. The question is what do you consider to be an urban area? Maybe the right technique here would be to look at road density - take this tile of Chicago for example:

http://1.base.maps.cit.api.here.com/maptile/2.1/basetile/newest/normal.day.grey/zoom/column/row/128/png8?app_id=AppID&app_code=AppCode

enter image description here

It is fairly obvious that the average color of the top half of the tile will be "greyer" than the bottom half. You could analyze the average pixel over a larger area to make your bit mask.

The final result will look something like this:

enter image description here

White pixel in mini-map = urban area. The projection is wrong for this image, but you'll get the idea.

3) Check for Forest.

This could be a "green pixel" check on the ordinary base map tiles: http://1.base.maps.cit.api.here.com/maptile/2.1/xbasetile/newest/normal.day//zoom/column/row/128/png8?app_id=AppID&app_code=AppCode

enter image description here

You'd need be careful with this forests don't appear to be consistently rendered over different zoom levels.

You can use the following calculation to find the xTile and yTile values from your longitude and latitiude. Obviously zoom will be fixed based on the size of your mini-map

latRad = lat * Math.PI / 180;
n = Math.pow(2, z);
xTile = n * ((lon + 180) / 360);
yTile = n * (1-(Math.log(Math.tan(latRad) + 1/Math.cos(latRad)) /
Math.PI)) / 2;
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top