English 中文(简体)
Algorithm 用于计算 go湖地图路线上的点
原标题:Algorithm for calculating points on the google map route for android

我一直在开发一个天然气站公司的roid申请。 申请使用权图。

The user selects two points on the map and i show the route between selected points. The application needs to show nearest(in 2 miles radius) gas stations on the selected route.

The route is a coordinate array like: Route[5000] = {"lon1,lat1","lon2,lat2","lon3,lat3","lon4,lat5"... }

And i have a gas stations list which consists of coordinates. GasStations[200] = {"lon1,lat1","lon2,lat2","lon3,lat3","lon4,lat5"... }

您可以建议我计算路线上最接近的天然气站的高性能算法。

感谢。

最佳回答

我不熟悉甲状腺。 此处,C#方法计算两个楼梯之间的距离。 如果距离在2英里半径之内,则该站就座。

是的,你将不得不通过5000x200 = 1 000 000 000,但速度相当快。

我希望这将有助于。

decimal distance = CalculateDistance(stationLatitude, stationLongitude, routeLatitude, routeLongitude);

private static double ToRadian(double val)
{
    return (Math.PI / 180) * val;
}

private static double ToXAxis(decimal lat, decimal lng)
{
    return (Math.Cos(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lat) *
        Math.Cos(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lng));
}

private static double ToYAxis(decimal lat, decimal lng)
{
    return (Math.Cos(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lat) *
        Math.Sin(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lng));
}

private static double ToZAxis(decimal lat)
{
    return Math.Sin(4 * (4 * Math.Atan2(1, 5) - Math.Atan2(1, 239)) / 180 * (double)lat);
}

private static decimal CalculateDistance(decimal lat1, decimal lng1, decimal lat2, decimal lng2)
{
    double cntXAxis = Math.Cos(ToRadian((double) lat1))*Math.Cos(ToRadian((double) lng1));
    double cntYAxis = Math.Cos(ToRadian((double) lat1))*Math.Sin(ToRadian((double) lng1));
    double cntZAxis = Math.Sin(ToRadian((double) lat1));

    return (decimal) (3961*Math.Acos(ToXAxis(lat2, lng2)*cntXAxis + ToYAxis(lat2, lng2)*cntYAxis + ToZAxis(lat2)*cntZAxis));
}
问题回答

暂无回答




相关问题
Android - ListView fling gesture triggers context menu

I m relatively new to Android development. I m developing an app with a ListView. I ve followed the info in #1338475 and have my app recognizing the fling gesture, but after the gesture is complete, ...

AsyncTask and error handling on Android

I m converting my code from using Handler to AsyncTask. The latter is great at what it does - asynchronous updates and handling of results in the main UI thread. What s unclear to me is how to handle ...

Android intent filter for a particular file extension?

I want to be able to download a file with a particular extension from the net, and have it passed to my application to deal with it, but I haven t been able to figure out the intent filter. The ...

Android & Web: What is the equivalent style for the web?

I am quite impressed by the workflow I follow when developing Android applications: Define a layout in an xml file and then write all the code in a code-behind style. Is there an equivalent style for ...

TiledLayer equivalent in Android [duplicate]

To draw landscapes, backgrounds with patterns etc, we used TiledLayer in J2ME. Is there an android counterpart for that. Does android provide an option to set such tiled patterns in the layout XML?

Using Repo with Msysgit

When following the Android Open Source Project instructions on installing repo for use with Git, after running the repo init command, I run into this error: /c/Users/Andrew Rabon/bin/repo: line ...

Android "single top" launch mode and onNewIntent method

I read in the Android documentation that by setting my Activity s launchMode property to singleTop OR by adding the FLAG_ACTIVITY_SINGLE_TOP flag to my Intent, that calling startActivity(intent) would ...

From Web Development to Android Development

I have pretty good skills in PHP , Mysql and Javascript for a junior developer. If I wanted to try my hand as Android Development do you think I might find it tough ? Also what new languages would I ...

热门标签