我正在開發Android
MapView
並開發基於地圖的應用程序。我需要從特定的Co-ordinates
找到X距離。方向不是我的優先距離是我的首要任務說,我需要找到100米從一個特定的位置任何想法我怎麼能做到這一點 預先感謝閱讀和回答。Android從已定義的位置查找X點的緯度經度
4
A
回答
7
爲了計算找到距離原點給定距離的線上的點,您需要有一個方位(或方向)以及距離。這是一個函數,它將採用起始位置,方位和距離(深度)並返回目標位置(對於Android):您可能希望將其從KM轉換爲Meters或其他任何位置。
public static Location GetDestinationPoint(Location startLoc, float bearing, float depth)
{
Location newLocation = new Location("newLocation");
double radius = 6371.0; // earth's mean radius in km
double lat1 = Math.toRadians(startLoc.getLatitude());
double lng1 = Math.toRadians(startLoc.getLongitude());
double brng = Math.toRadians(bearing);
double lat2 = Math.asin(Math.sin(lat1)*Math.cos(depth/radius) + Math.cos(lat1)*Math.sin(depth/radius)*Math.cos(brng));
double lng2 = lng1 + Math.atan2(Math.sin(brng)*Math.sin(depth/radius)*Math.cos(lat1), Math.cos(depth/radius)-Math.sin(lat1)*Math.sin(lat2));
lng2 = (lng2+Math.PI)%(2*Math.PI) - Math.PI;
// normalize to -180...+180
if (lat2 == 0 || lng2 == 0)
{
newLocation.setLatitude(0.0);
newLocation.setLongitude(0.0);
}
else
{
newLocation.setLatitude(Math.toDegrees(lat2));
newLocation.setLongitude(Math.toDegrees(lng2));
}
return newLocation;
};
1
只是爲了從javram回答米和弧度而不是度數。
/**
* Create a new location specified in meters and bearing from a previous location.
* @param startLoc from where
* @param bearing which direction, in radians from north
* @param distance meters from startLoc
* @return a new location
*/
public static Location createLocation(Location startLoc, double bearing, double distance) {
Location newLocation = new Location("newLocation");
double radius = 6371000.0; // earth's mean radius in m
double lat1 = Math.toRadians(startLoc.getLatitude());
double lng1 = Math.toRadians(startLoc.getLongitude());
double lat2 = Math.asin(Math.sin(lat1) * Math.cos(distance/radius) + Math.cos(lat1) * Math.sin(distance/radius) * Math.cos(bearing));
double lng2 = lng1 + Math.atan2(Math.sin(bearing) * Math.sin(distance/radius) * Math.cos(lat1), Math.cos(distance/radius) - Math.sin(lat1) * Math.sin(lat2));
lng2 = (lng2 + Math.PI) % (2 * Math.PI) - Math.PI;
// normalize to -180...+180
if (lat2 == 0 || lng2 == 0) {
newLocation.setLatitude(0.0);
newLocation.setLongitude(0.0);
} else {
newLocation.setLatitude(Math.toDegrees(lat2));
newLocation.setLongitude(Math.toDegrees(lng2));
}
return newLocation;
}
相關問題
- 1. android經緯度位置查找器
- 2. 使用API查找已知位置的經度和緯度?
- 3. 從已知位置確定預測的經度/緯度
- 4. 經度緯度點的奇怪位置
- 5. 如何查找特定位置的經度和緯度?
- 6. 如何查找距某點X距離的經度和緯度?
- 7. iOS從郵政編碼查找位置(經度,緯度)
- 8. 用於查找位置數量的經度和緯度的JavaScript
- 9. 如何從給定的經緯度找到經度爲X(k)米的緯度/經度?
- 10. 查找經度和緯度
- 11. 找到當前位置的經緯度
- 12. 找不到用戶的位置: - 緯度和經度在android
- 13. 如何從給定的經度和緯度查找位置名稱?
- 14. 附近地點的經緯度位置
- 15. 查找當前位置的經度和緯度
- 16. 是否有Java API來查找位置的經度和緯度?
- 17. 如何從android的位置服務獲取緯度和經度
- 18. 限制位置的經度和緯度
- 19. NullPointerException經度和緯度上的位置
- 20. JSON經度緯度最近的位置
- 21. 位置的經度和緯度
- 22. 從經緯度的iOS位置
- 23. 通過緯度和經度查找位置
- 24. 查找子公司經度和緯度(地理位置)
- 25. 如何找到緯度/經度/緯度點之間的距離?
- 26. Android的檢查,如果我的緯度/經度位置withing給定區域
- 27. Google Maps JS API - 查找給定位置的名稱(經度/緯度)
- 28. 如何從iPhone中的另外兩個位置查找經度和緯度?
- 29. 如何從地址/位置(經度和緯度)查找地標的圖片
- 30. Android地理位置打印經緯度
我該如何使用這個與geopoints? –
只需將位置轉換爲地理位置: int lat =(int)(location.getLatitude()* 1E6); int lng =(int)(location.getLongitude()* 1E6); GeoPoint point = new GeoPoint(lat,lng); – javram
我不明白軸承是如何工作的?它是在0-360之間嗎?這似乎並不奏效。謝謝 – aidanmack