Calculate latitudeDelta and longitudeDelta in titanium maps [Android]

不羁的心 提交于 2019-12-08 11:31:23

问题


I need a help in showing the correct zoom level in Titanium maps for Android.

I am showing the route from current location to some other location.The distance is different every time. Can it be possible that I calculate the values of latitudeDelta and longitudeDelta based on the distance and show the map zoomed up according to that? If yes, how could it be possible?

Thanks in advance!


回答1:


As the the documentation states the smaller the delta value, the closer the zoom on your map. That means 0.01 will zoom in more as compared to 0.1 for delta (latitude, longitude). As these values are hardcoded in the regions parameter, I would recommend is to use a function that would dynamically populate latitudeDelta: & longitudeDelta: based on the distance. So if the distance is more you can have a higher value for delta's else lesser values.

Here is one such function:

function distanceToZoom( r ){
    var w = myMapInstance.getSize().width;
    var d = r * 2;
    var distance = [you can put distances in this array];
    var z = 20, m;
    while( distance[--z] ){
        m = distance[z] * w;
        if( d < m ){
            break;
        }
    }
    return z;
} 

To corresponding delta values:

delta distance in miles (Supposedly)
0.0001  10
 0.001  100
  0.01  1000
   0.1  10000
   1    10000

Hope this Helps!!



来源:https://stackoverflow.com/questions/28935091/calculate-latitudedelta-and-longitudedelta-in-titanium-maps-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!