下面为将机器人的轨迹对应到谷歌地球上的demo,只需要将
X-GPS Explorer
Place Mark
My Path
114.3550997,30.53966355
114.3551003,30.53966349
114.3551008,30.53966342
114.3551014,30.53966335
114.3551019,30.53966328
114.3551025,30.53966317
114.3551031,30.53966305
114.3551037,30.53966294
114.3551043,30.53966283
114.3551049,30.53966272
114.3551055,30.5396626
114.3551061,30.53966249
114.3551067,30.53966237
114.3551073,30.53966225
114.3551079,30.53966215
114.3551085,30.53966202
114.3551091,30.53966189
114.3551096,30.53966176
114.3551102,30.53966165
114.3551107,30.53966154
114.3551113,30.53966145
114.3551119,30.53966137
114.3551124,30.53966129
114.355113,30.53966123
114.3551136,30.53966116
114.3551143,30.53966103
114.355115,30.53966089
114.3551157,30.53966076
114.3551164,30.53966063
114.355117,30.5396605
114.3551177,30.53966037
114.3551184,30.53966025
114.3551191,30.53966013
114.3551198,30.53966002
114.3551205,30.5396599
114.3551211,30.53965986
114.3551217,30.53965985
114.3551224,30.53965983
114.355123,30.53965981
114.3551236,30.53965978
114.3551242,30.53965974
114.3551248,30.53965971
114.3551255,30.53965965
114.3551261,30.53965959
114.3551267,30.53965952
114.3551273,30.5396595
114.3551278,30.53965947
114.3551284,30.53965944
114.3551289,30.53965941
114.3551294,30.53965938
114.35513,30.53965935
再分享个将经纬度坐标与xy坐标相互转换的两个头文件,我忘记在哪儿找到的了,现贴在下面,免得自已有需要的时候又找不到了,就酱。然后下面两个代码我挂到llandxy.zip上面去卖积分了,大佬们如果觉得这两个代码对你很有帮助,而你的积分又有很多的话,帮忙去那里面下,赏我两个积分^_^。
“convert_coordinates.hpp”
// Author: Andreas Geiger
#if !defined(CONVERT_COORDINATES_HPP)
#define CONVERT_COORDINATES_HPP
#define M_PI 3.141593
#include
/*!
* \file convert_coordinates.hpp
*
* \brief provides functions to convert global lat/long into local cartesian x/y coordinates
*
* the following functions map lat/long coordinates to the euclidean mercator coordinate system mx/my
* lat/long are always specified in degrees (DEG)
* mx is the distance from the central meridian towards EAST
* my is the distance from the equator towards NORTH
* mercator cordinates mx/my correspond to metric coordinates x/y ONLY at the equator (scale=1)
* at other latitudes a scale factor can be used to get metric relations
* for more details see GCDC/docs/coordinate_systems.pdf
* \note that in GCDC x is towards NORTH, y towards WEST!!!
*/
namespace convert_coordinates {
const double EARTH_RADIUS_EQUA = 6378137.0;// earth radius at equator [m]
// inlined functions to avoid multiple definitions
/*! \brief convert latitude to scale, which is needed by mercator transformations
* \param lat latitude in degrees (DEG)
* \return scale factor
* \note when converting from lat/lon -> mercator and back again,
* or vice versa, use the same scale in both transformations!
*/
inline double lat_to_scale (double lat) {
return cos(lat * M_PI / 180.0);
}
/*! \brief converts lat/lon/scale to mx/my (mx/my in meters if correct scale is given)
*/
template
inline void latlon_to_mercator (double lat, double lon, double scale, float_type &mx, float_type &my) {
mx = scale * lon * M_PI * EARTH_RADIUS_EQUA / 180.0;
my = scale * EARTH_RADIUS_EQUA * log( tan((90.0+lat) * M_PI / 360.0) );
}
/*! \brief convenience function, uses lat0 to calculate appropriate scale
*/
inline void latlon_to_scaled_mercator (double lat, double lon, double lat0, double &mx, double &my) {
double scale = lat_to_scale( lat0 );
mx = scale * lon * M_PI * EARTH_RADIUS_EQUA / 180.0;
my = scale * EARTH_RADIUS_EQUA * log( tan((90.0+lat) * M_PI / 360.0) );
}
/*! \brief converts mx/my/scale to lat/lon (mx/my in meters if correct scale is given)
*/
inline void mercator_to_latlon (double mx, double my, double scale, double &lat, double &lon) {
lon = mx * 180.0 / (M_PI * EARTH_RADIUS_EQUA * scale);
lat = 360.0 * atan( exp(my/(EARTH_RADIUS_EQUA * scale)) ) / M_PI - 90.0;
}
/*! \brief convenience function, uses lat0 to calculate appropriate scale
*/
inline void scaled_mercator_to_latlon (double mx, double my, double lat0, double &lat, double &lon) {
double scale = lat_to_scale( lat0 );
lon = mx * 180.0 / (M_PI * EARTH_RADIUS_EQUA * scale);
lat = 360.0 * atan( exp(my/(EARTH_RADIUS_EQUA * scale)) ) / M_PI - 90.0;
}
/*! \brief adds meters dx/dy to given lat/lon and returns new lat/lon
*/
inline void latlon_add_meters (double lat_start, double lon_start, double dx, double dy, double &lat_end, double &lon_end) {
double scale = lat_to_scale (lat_start);
double mx,my;
latlon_to_mercator (lat_start, lon_start, scale, mx, my);
mx += dx;
my += dy;
mercator_to_latlon (mx, my, scale, lat_end, lon_end);
}
/*! \brief given two lat/lon coordinates, returns their difference in meters dx/dy
*/
inline void latlon_diff_to_meters (double lat_start, double lon_start, double lat_end, double lon_end, double &dx, double &dy) {
double scale = lat_to_scale (lat_start);
double mx1,my1, mx2, my2;
latlon_to_mercator (lat_start, lon_start, scale, mx1, my1);
latlon_to_mercator (lat_end, lon_end, scale, mx2, my2);
dx = mx2-mx1;
dy = my2-my1;
}
};
#endif
“LocalGeographicCS.hpp”
// File: LocalGeographicCS.hpp
// Creation Date: Tuesday, March 6 2012
// Author: Julius Ziegler
#if !defined(LOCALGEOGRAPHICCS_HPP)
#define LOCALGEOGRAPHICCS_HPP
#include "convert_coordinates.hpp"
#include
struct LocalGeographicCS
{
LocalGeographicCS();
LocalGeographicCS( double lat0, double lon0 );
void set_origin( double lat0, double lon0 );
void ll2xy( double lat, double lon, double& x, double& y ) const;
void xy2ll( double x, double y, double& lat, double& lon ) const;
std::pair ll2xy( double lat, double lon ) const;
std::pair xy2ll( double x, double y ) const;
// operate on containers
template
void ll2xy( const ItIn& lat_begin, const ItIn& lat_end, const ItIn& lon_begin, const ItOut& x_begin, const ItOut& y_begin ) const;
template
void xy2ll( const ItIn& x_begin, const ItIn& x_end, const ItIn& y_begin, const ItOut& lat_begin, const ItOut& lon_begin ) const;
//get coords
double get_coordx();
double get_coordy();
private:
double _scale;
double _x0, _y0;
};
inline double LocalGeographicCS::get_coordx()
{
return _x0;
}
inline double LocalGeographicCS::get_coordy()
{
return _y0;
}
inline LocalGeographicCS::LocalGeographicCS( double lat0, double lon0 )
{
set_origin( lat0, lon0 );
}
inline LocalGeographicCS::LocalGeographicCS()
{}
inline void LocalGeographicCS::set_origin( double lat0, double lon0 )
{
_scale = convert_coordinates::lat_to_scale( lat0 );
convert_coordinates::latlon_to_mercator( lat0, lon0, _scale, _x0, _y0 );
}
inline void LocalGeographicCS::ll2xy( double lat, double lon, double& x, double& y ) const
{
convert_coordinates::latlon_to_mercator( lat, lon, _scale, x, y );
// printf("&&&&&&&&&&&& %.6f %.6f\n", _x0, _y0);
x -= _x0;
y -= _y0;
}
inline std::pair LocalGeographicCS::ll2xy( double lat, double lon ) const
{
double x, y;
ll2xy( lat, lon, x, y );
return std::make_pair( x, y );
}
inline void LocalGeographicCS::xy2ll( double x, double y, double& lat, double& lon ) const
{
x += _x0;
y += _y0;
convert_coordinates::mercator_to_latlon( x, y, _scale, lat, lon );
}
inline std::pair LocalGeographicCS::xy2ll( double x, double y ) const
{
double lat, lon;
xy2ll( x, y, lat, lon );
return std::make_pair( lat, lon );
}
// operate on containers
template
void LocalGeographicCS::ll2xy( const ItIn& lat_begin, const ItIn& lat_end, const ItIn& lon_begin, const ItOut& x_begin, const ItOut& y_begin ) const
{
ItIn lat = lat_begin;
ItIn lon = lon_begin;
ItOut x = x_begin;
ItOut y = y_begin;
for( ; lat != lat_end; lat++, lon++, x++, y++ )
{
ll2xy( *lat, *lon, *x, *y );
}
}
template
void LocalGeographicCS::xy2ll( const ItIn& x_begin, const ItIn& x_end, const ItIn& y_begin, const ItOut& lat_begin, const ItOut& lon_begin ) const
{
ItIn x = x_begin;
ItIn y = y_begin;
ItOut lat = lat_begin;
ItOut lon = lon_begin;
for( ; x != x_end; lat++, lon++, x++, y++ )
xy2ll( *x, *y, *lat, *lon );
}
#endif