计算增加高度的经纬度
Calculate latitude longitude for added height
我想在 Android google 地图上绘制折线图。
我有路径的 gps 坐标,我想在地图上用线的高度显示汽车的速度。
看到这张图片 有点像这样,
对于每个 gps (lat,lng) 点,我想添加一些高度并计算相应的 gps(lat,lng) 点。我想在 3D 视图中显示它,所以当相机位置改变时我将不得不改变点,但第一步是用增加的高度计算 gps 点。
例如
ArrayList<LatLng> basePoints = new ArrayList<LatLng>();
basePoints.add(new LatLng(53.262688, -2.500792));
basePoints.add(new LatLng(53.262758, -2.500897));
basePoints.add(new LatLng(53.262789, -2.501087));
basePoints.add(new LatLng(53.262798, -2.501229));
basePoints.add(new LatLng(53.262785, -2.501414));
basePoints.add(new LatLng(53.262760, -2.501594));
basePoints.add(new LatLng(53.262707, -2.501811));
basePoints.add(new LatLng(53.262655, -2.501943));
ArrayList<LatLng> topPoints = new ArrayList<LatLng>();
topPoints.add(new LatLng(53.262939, -2.500779));
topPoints.add(new LatLng(53.262975, -2.500916));
topPoints.add(new LatLng(53.262914, -2.501098));
topPoints.add(new LatLng(53.263055, -2.501248));
topPoints.add(new LatLng(53.262925, -2.501439));
topPoints.add(new LatLng(53.263045, -2.501581));
topPoints.add(new LatLng(53.262907, -2.501844));
topPoints.add(new LatLng(53.263002, -2.502015));
知道我该怎么做吗?
谢谢
计算一米是多少度:
在赤道:
360度,
有 40.000 000 米 circumfene.
所以一米大约是
double static final METERS_PER_DEGREE = 360.0 / 40 000 000;
现在将纬度偏移例如 3 米:
lat = lat + 3 * METERS_PER_DEGREE.
偏移经度时,必须乘以cos(Math.toRadians(latitude);
double oneMeterLongitudeInDegrees = METERS_PER_DEGREE * cos(Math.toRadians(latitude);
lonNew = lonOld + 3 * oneMeterLongitudeInDegrees
根据你提供的 link 我已经为你实现了这个。
final ArrayList<LatLng> basePoints = new ArrayList<LatLng>();
basePoints.add(new LatLng(53.262688, -2.500792));
basePoints.add(new LatLng(53.262758, -2.500897));
basePoints.add(new LatLng(53.262789, -2.501087));
basePoints.add(new LatLng(53.262798, -2.501229));
basePoints.add(new LatLng(53.262785, -2.501414));
basePoints.add(new LatLng(53.262760, -2.501594));
basePoints.add(new LatLng(53.262707, -2.501811));
basePoints.add(new LatLng(53.262655, -2.501943));
final ArrayList<Double> speedPoints = new ArrayList<Double>();
speedPoints.add(7.955734692);
speedPoints.add(8.761378798);
speedPoints.add(11.07760474);
speedPoints.add(13.69594751);
speedPoints.add(15.50864695);
speedPoints.add(16.01217576);
speedPoints.add(15.60935179);
speedPoints.add(15.71005663);
LatLngBounds.Builder bounds = new LatLngBounds.Builder();
for(int i=0;i<basePoints.size();i++)
{
bounds.include(basePoints.get(i));
}
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 300,300,0));
map.setOnCameraChangeListener(new OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition arg0)
{
map.clear();
ArrayList<LatLng> topPoints = new ArrayList<LatLng>();
for(int i=0;i<basePoints.size();i++)
{
topPoints.add(moveByDistance(basePoints.get(i), speedPoints.get(i)*3,map.getCameraPosition().bearing));
}
PolylineOptions topPO = new PolylineOptions();
topPO.addAll(topPoints).width(5).color(Color.BLUE).geodesic(true);
map.addPolyline(topPO);
for(int i=0;i<basePoints.size()-1;i++)
{
map.addPolygon(new PolygonOptions().add(basePoints.get(i),topPoints.get(i),topPoints.get(i+1),basePoints.get(i+1),basePoints.get(i)).fillColor(Color.YELLOW).strokeColor(Color.YELLOW));
}
}
});
/**
* Move a LatLng-Point into a given distance and a given angle (0-360,
* 0=North).
*/
public static LatLng moveByDistance(LatLng startGp, double distance,double angle) {
/*
* Calculate the part going to north and the part going to east.
*/
double arc = Math.toRadians(angle);
double toNorth = distance * Math.cos(arc);
double toEast = distance * Math.sin(arc);
double lonDiff = meterToLongitude(toEast, startGp.latitude);
double latDiff = meterToLatitude(toNorth);
return new LatLng(startGp.latitude + latDiff, startGp.longitude + lonDiff);
}
private static double meterToLongitude(double meterToEast, double latitude) {
double latArc = Math.toRadians(latitude);
double radius = Math.cos(latArc) * EARTHRADIUS;
double rad = meterToEast / radius;
double degrees = Math.toDegrees(rad);
return degrees;
}
private static double meterToLatitude(double meterToNorth) {
double rad = meterToNorth / EARTHRADIUS;
double degrees = Math.toDegrees(rad);
return degrees;
}
我希望它能帮助你实现这个。
我想在 Android google 地图上绘制折线图。 我有路径的 gps 坐标,我想在地图上用线的高度显示汽车的速度。
看到这张图片 有点像这样,
对于每个 gps (lat,lng) 点,我想添加一些高度并计算相应的 gps(lat,lng) 点。我想在 3D 视图中显示它,所以当相机位置改变时我将不得不改变点,但第一步是用增加的高度计算 gps 点。
例如
ArrayList<LatLng> basePoints = new ArrayList<LatLng>();
basePoints.add(new LatLng(53.262688, -2.500792));
basePoints.add(new LatLng(53.262758, -2.500897));
basePoints.add(new LatLng(53.262789, -2.501087));
basePoints.add(new LatLng(53.262798, -2.501229));
basePoints.add(new LatLng(53.262785, -2.501414));
basePoints.add(new LatLng(53.262760, -2.501594));
basePoints.add(new LatLng(53.262707, -2.501811));
basePoints.add(new LatLng(53.262655, -2.501943));
ArrayList<LatLng> topPoints = new ArrayList<LatLng>();
topPoints.add(new LatLng(53.262939, -2.500779));
topPoints.add(new LatLng(53.262975, -2.500916));
topPoints.add(new LatLng(53.262914, -2.501098));
topPoints.add(new LatLng(53.263055, -2.501248));
topPoints.add(new LatLng(53.262925, -2.501439));
topPoints.add(new LatLng(53.263045, -2.501581));
topPoints.add(new LatLng(53.262907, -2.501844));
topPoints.add(new LatLng(53.263002, -2.502015));
知道我该怎么做吗? 谢谢
计算一米是多少度:
在赤道:
360度, 有 40.000 000 米 circumfene.
所以一米大约是
double static final METERS_PER_DEGREE = 360.0 / 40 000 000;
现在将纬度偏移例如 3 米:
lat = lat + 3 * METERS_PER_DEGREE.
偏移经度时,必须乘以cos(Math.toRadians(latitude);
double oneMeterLongitudeInDegrees = METERS_PER_DEGREE * cos(Math.toRadians(latitude);
lonNew = lonOld + 3 * oneMeterLongitudeInDegrees
根据你提供的 link 我已经为你实现了这个。
final ArrayList<LatLng> basePoints = new ArrayList<LatLng>();
basePoints.add(new LatLng(53.262688, -2.500792));
basePoints.add(new LatLng(53.262758, -2.500897));
basePoints.add(new LatLng(53.262789, -2.501087));
basePoints.add(new LatLng(53.262798, -2.501229));
basePoints.add(new LatLng(53.262785, -2.501414));
basePoints.add(new LatLng(53.262760, -2.501594));
basePoints.add(new LatLng(53.262707, -2.501811));
basePoints.add(new LatLng(53.262655, -2.501943));
final ArrayList<Double> speedPoints = new ArrayList<Double>();
speedPoints.add(7.955734692);
speedPoints.add(8.761378798);
speedPoints.add(11.07760474);
speedPoints.add(13.69594751);
speedPoints.add(15.50864695);
speedPoints.add(16.01217576);
speedPoints.add(15.60935179);
speedPoints.add(15.71005663);
LatLngBounds.Builder bounds = new LatLngBounds.Builder();
for(int i=0;i<basePoints.size();i++)
{
bounds.include(basePoints.get(i));
}
map.moveCamera(CameraUpdateFactory.newLatLngBounds(bounds.build(), 300,300,0));
map.setOnCameraChangeListener(new OnCameraChangeListener() {
@Override
public void onCameraChange(CameraPosition arg0)
{
map.clear();
ArrayList<LatLng> topPoints = new ArrayList<LatLng>();
for(int i=0;i<basePoints.size();i++)
{
topPoints.add(moveByDistance(basePoints.get(i), speedPoints.get(i)*3,map.getCameraPosition().bearing));
}
PolylineOptions topPO = new PolylineOptions();
topPO.addAll(topPoints).width(5).color(Color.BLUE).geodesic(true);
map.addPolyline(topPO);
for(int i=0;i<basePoints.size()-1;i++)
{
map.addPolygon(new PolygonOptions().add(basePoints.get(i),topPoints.get(i),topPoints.get(i+1),basePoints.get(i+1),basePoints.get(i)).fillColor(Color.YELLOW).strokeColor(Color.YELLOW));
}
}
});
/**
* Move a LatLng-Point into a given distance and a given angle (0-360,
* 0=North).
*/
public static LatLng moveByDistance(LatLng startGp, double distance,double angle) {
/*
* Calculate the part going to north and the part going to east.
*/
double arc = Math.toRadians(angle);
double toNorth = distance * Math.cos(arc);
double toEast = distance * Math.sin(arc);
double lonDiff = meterToLongitude(toEast, startGp.latitude);
double latDiff = meterToLatitude(toNorth);
return new LatLng(startGp.latitude + latDiff, startGp.longitude + lonDiff);
}
private static double meterToLongitude(double meterToEast, double latitude) {
double latArc = Math.toRadians(latitude);
double radius = Math.cos(latArc) * EARTHRADIUS;
double rad = meterToEast / radius;
double degrees = Math.toDegrees(rad);
return degrees;
}
private static double meterToLatitude(double meterToNorth) {
double rad = meterToNorth / EARTHRADIUS;
double degrees = Math.toDegrees(rad);
return degrees;
}
我希望它能帮助你实现这个。