我想在Android谷歌地图上绘制折线图。 我有路径的gps坐标,我想用线的高度来显示地图上汽车的速度。
看到这张图片像这样,
对于每个gps(lat,lng)点,我想添加一些高度并计算相应的gps(lat,lng)点。我想在3D视图中显示这个,所以我必须在相机位置改变时更改点,但第一步是计算增加高度的gps点。
例如
@Repository
@Transactional
@EnableScheduling
public class NotificationDAOImpl implements NotificationDAO{
@Override
@Scheduled(cron = "0 3 3 * * ?")
public void deleteNotificationsAutoMagically(){
session=this.sessionFactory.getCurrentSession();
long now = System.currentTimeMillis();
long nowMinus1Week = now - (1000 * 60 * 60 * 24 * 3);
Timestamp nowMinus1WeekAsTimeStamp = new Timestamp(nowMinus1Week);
Query query = session.createQuery("delete from NoteLock as nl where nl.timestamp < :limit and nl.read=:true");
query.setParameter("limit", nowMinus1WeekAsTimeStamp);
query.executeUpdate();
session.flush();
}
}
知道我该怎么办? 感谢
答案 0 :(得分:1)
计算一米多少度:
在赤道上:
360度, 有40万000米的环绕声。
所以一米是关于
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
答案 1 :(得分:1)
从您提供的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;
}
我希望它能帮助您实现这一目标。