如何在地图上标点轨迹

|  
|  
|  
|  
|  
只需一步,快速开始
查看: 2203|回复: 5
请教地图是键盘上那个键
主题帖子积分
超级玩家, 积分 859, 距离下一级还需 141 积分
超级玩家, 积分 859, 距离下一级还需 141 积分
请教地图是键盘上那个键
主题帖子积分
高级玩家, 积分 302, 距离下一级还需 298 积分
高级玩家, 积分 302, 距离下一级还需 298 积分
我的是enter键
主题帖子积分
超级玩家, 积分 921, 距离下一级还需 79 积分
超级玩家, 积分 921, 距离下一级还需 79 积分
在设置里面把开地图的10号键设置成你想用的键就好了。。。
主题帖子积分
游戏狂人, 积分 1706, 距离下一级还需 294 积分
游戏狂人, 积分 1706, 距离下一级还需 294 积分
我改不了不知道为什么,改了就反应
主题帖子积分
中级玩家, 积分 108, 距离下一级还需 142 积分
中级玩家, 积分 108, 距离下一级还需 142 积分
在野外打开小地图是哪个啊??
主题帖子积分
高级玩家, 积分 587, 距离下一级还需 13 积分
高级玩家, 积分 587, 距离下一级还需 13 积分
ms220 发表于
在野外打开小地图是哪个啊??
野外小地图是6号键也就是默认的E这个按键= =
Powered by8511人阅读
IOS(109)
iOS中的MapKit集成了google地图api的很多功能加上iOS的定位的功能,我们就可以实现将你运行的轨迹绘制到地图上面。这个功能非常有用,比如快递追踪、汽车的gprs追踪、人员追踪等等。这篇文章我们将使用Map Kit和iOS的定位功能,将你的运行轨迹绘制在地图上面。
&& 在之前的一篇文章描述了如何在地图上显示自己的位置,如果我们将这些位置先保存起来,然后串联起来绘制到地图上面,那就是我们的运行轨迹了。
&&& 首先我们看下如何在地图上绘制曲线。在Map Kit中提供了一个叫MKPolyline的类,我们可以利用它来绘制曲线,先看个简单的例子。
&&& 使用下面代码从一个文件中读取出经纬度,然后创建一个路径:MKPolyline实例。
-(void) loadRoute& {& NSString* filePath = [[NSBundle mainBundle] pathForResource:@”route” ofType:@”csv”];&NSString* fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];&NSArray* pointStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];&& // while we create the route points, we will also be calculating the bounding box of our route&// so we can easily zoom in on it.& MKMapPoint northEastP& MKMapPoint southWestP&& & // create a c array of points.& MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * pointStrings.count);&& for(int idx = 0; idx & pointStrings. idx++)& {& // break the string down even further to latitude and longitude fields.&NSString* currentPointString = [pointStrings objectAtIndex:idx];&
NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@&,&]];&& CLLocationDegrees latitude = [[latLonArr objectAtIndex:0] doubleValue];&CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];&& // create our coordinate and add it to the correct spot in the array&
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);&& MKMapPoint point = MKMapPointForCoordinate(coordinate);&
& //& // adjust the bounding box& //& & // if it is the first point, just use them, since we have nothing to compare to yet.&if (idx == 0) {& northEastPoint =& southWestPoint =& }& else& {& if (point.x & northEastPoint.x)& northEastPoint.x = point.x;& if(point.y & northEastPoint.y)& northEastPoint.y = point.y;& if (point.x & southWestPoint.x)& southWestPoint.x = point.x;& if (point.y & southWestPoint.y)& southWestPoint.y = point.y;& }& & pointArr[idx] =& & }& & // create the polyline based on the array of points.& self.routeLine = [MKPolyline polylineWithPoints:pointArr count:pointStrings.count];&& _routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);& // clear the memory allocated earlier for the points&
free(pointArr);& & }&&
-(void) loadRoute
NSString* filePath = [[NSBundle mainBundle] pathForResource:@”route” ofType:@”csv”];
NSString* fileContents = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSArray* pointStrings = [fileContents componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// while we create the route points, we will also be calculating the bounding box of our route
// so we can easily zoom in on it.
MKMapPoint northEastP
MKMapPoint southWestP
// create a c array of points.
MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * pointStrings.count);
for(int idx = 0; idx & pointStrings. idx++)
// break the string down even further to latitude and longitude fields.
NSString* currentPointString = [pointStrings objectAtIndex:idx];
NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@&,&]];
CLLocationDegrees latitude = [[latLonArr objectAtIndex:0] doubleValue];
CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];
// create our coordinate and add it to the correct spot in the array
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
MKMapPoint point = MKMapPointForCoordinate(coordinate);
// adjust the bounding box
// if it is the first point, just use them, since we have nothing to compare to yet.
if (idx == 0) {
northEastPoint =
southWestPoint =
if (point.x & northEastPoint.x)
northEastPoint.x = point.x;
if(point.y & northEastPoint.y)
northEastPoint.y = point.y;
if (point.x & southWestPoint.x)
southWestPoint.x = point.x;
if (point.y & southWestPoint.y)
southWestPoint.y = point.y;
pointArr[idx] =
// create the polyline based on the array of points.
self.routeLine = [MKPolyline polylineWithPoints:pointArr count:pointStrings.count];
_routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);
// clear the memory allocated earlier for the points
free(pointArr);
将这个路径添加到地图上
[self.mapView addOverlay:self.routeLine];&&
[self.mapView addOverlay:self.routeLine];
显示在地图上:
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay&{& MKOverlayView* overlayView =& & if(overlay == self.routeLine)& {& //if we have not yet created an overlay view for this overlay, create it now.&if(nil == self.routeLineView)& {& self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];&self.routeLineView.fillColor = [UIColor redColor];&
self.routeLineView.strokeColor = [UIColor redColor];& self.routeLineView.lineWidth = 3;& }& & overlayView = self.routeLineV& & }& & return overlayV& & }&&
- (MKOverlayView *)mapView:(MKMapView *)mapView viewForOverlay:(id )overlay
MKOverlayView* overlayView =
if(overlay == self.routeLine)
//if we have not yet created an overlay view for this overlay, create it now.
if(nil == self.routeLineView)
self.routeLineView = [[[MKPolylineView alloc] initWithPolyline:self.routeLine] autorelease];
self.routeLineView.fillColor = [UIColor redColor];
self.routeLineView.strokeColor = [UIColor redColor];
self.routeLineView.lineWidth = 3;
overlayView = self.routeLineV
return overlayV
然后我们在从文件中读取位置的方法改成从用gprs等方法获取当前位置。
第一步:创建一个CLLocationManager实例
第二步:设置CLLocationManager实例委托和精度
第三步:设置距离筛选器distanceFilter
第四步:启动请求
代码如下:
- (void)viewDidLoad {& &&& [super viewDidLoad];& &&&&& &&& noUpdates = 0;& &&& locations = [[NSMutableArray alloc] init];& &&&&& &&& locationMgr = [[CLLocationManager alloc] init];&
&&& locationMgr.delegate =& &&& locationMgr.desiredAccuracy =kCLLocationAccuracyB&
&&& locationMgr.distanceFilter& = 1.0f;& &&& [locationMgr startUpdatingLocation];& &&&&& &&&&& }&
- (void)viewDidLoad {
[super viewDidLoad];
noUpdates = 0;
locations = [[NSMutableArray alloc] init];
locationMgr = [[CLLocationManager alloc] init];
locationMgr.delegate =
locationMgr.desiredAccuracy =kCLLocationAccuracyB
locationMgr.distanceFilter
[locationMgr startUpdatingLocation];
上面的代码我定义了一个数组,用于保存运行轨迹的经纬度。
每次通知更新当前位置的时候,我们将当前位置的经纬度放到这个数组中,并重新绘制路径,代码如下:
- (void)locationManager:(CLLocationManager *)manager&&&&& didUpdateToLocation:(CLLocation *)newLocation&& &&&&&&&&&& fromLocation:(CLLocation *)oldLocation{&
&&&&&& noUpdates++;& && &&&&&& [locations addObject: [NSString stringWithFormat:@&%f,%f&,[newLocation coordinate].latitude, [newLocation coordinate].longitude]];&&& &&&&&& [self updateLocation];& &&&&&&& if (self.routeLine!=nil) {& &&&&&&&&& self.routeLine =& &&&&&&& }& &&& if(self.routeLine!=nil)& &&&&&&&&& [self.mapView removeOverlay:self.routeLine];&
&&&&&&& self.routeLine =& &&& // create the overlay& &&& [self loadRoute];& &&&&& &&& // add the overlay to the map& &&& if (nil != self.routeLine) {& &&&&&&& [self.mapView addOverlay:self.routeLine];& &&& }& &&&&& &&& // zoom in on the route.&& &&& [self zoomInOnRoute];& &&&&&&&&&& }&
- (void)locationManager:(CLLocationManager *)manager
didUpdateToLocation:(CLLocation *)newLocation
fromLocation:(CLLocation *)oldLocation{
noUpdates++;
[locations addObject: [NSString stringWithFormat:@&%f,%f&,[newLocation coordinate].latitude, [newLocation coordinate].longitude]];
[self updateLocation];
if (self.routeLine!=nil) {
self.routeLine =
if(self.routeLine!=nil)
[self.mapView removeOverlay:self.routeLine];
self.routeLine =
// create the overlay
[self loadRoute];
// add the overlay to the map
if (nil != self.routeLine) {
[self.mapView addOverlay:self.routeLine];
// zoom in on the route.
[self zoomInOnRoute];
我们将前面从文件获取经纬度创建轨迹的代码修改成从这个数组中取值就行了:
// creates the route (MKPolyline) overlay& -(void) loadRoute& {& && &&&&& &&& // while we create the route points, we will also be calculating the bounding box of our route&&&& // so we can easily zoom in on it.&& &&& MKMapPoint northEastP&& &&& MKMapPoint southWestP&& &&&&& &&& // create a c array of points.&& &&& MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * locations.count);&&&& for(int idx = 0; idx & locations. idx++)&
&&& {& &&&&&&& // break the string down even further to latitude and longitude fields.&&&&&&&&& NSString* currentPointString = [locations objectAtIndex:idx];&
&&&&&&& NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@&,&]];&&&&&& &&&&&&& CLLocationDegrees latitude& = [[latLonArr objectAtIndex:0] doubleValue];&&&&&&&& CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];&&&&&&&&&&& &&&&&&& CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);&& &&&&&&& MKMapPoint point = MKMapPointForCoordinate(coordinate);&
& &&&&& &&&&&&& if (idx == 0) {& &&&&&&&&&&& northEastPoint =& &&&&&&&&&&& southWestPoint =& &&&&&&& }& &&&&&&& else&& &&&&&&& {& &&&&&&&&&&& if (point.x & northEastPoint.x)&& &&&&&&&&&&&&&&& northEastPoint.x = point.x;& &&&&&&&&&&& if(point.y & northEastPoint.y)& &&&&&&&&&&&&&&& northEastPoint.y = point.y;& &&&&&&&&&&& if (point.x & southWestPoint.x)&& &&&&&&&&&&&&&&& southWestPoint.x = point.x;& &&&&&&&&&&& if (point.y & southWestPoint.y)&& &&&&&&&&&&&&&&& southWestPoint.y = point.y;& &&&&&&& }& & &&&&&&& pointArr[idx] =& & &&& }& &&&&& &&& self.routeLine = [MKPolyline polylineWithPoints:pointArr count:locations.count];&& &&& _routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);&&&&&& &&& free(pointArr);& &&&&& }&
// creates the route (MKPolyline) overlay
-(void) loadRoute
// while we create the route points, we will also be calculating the bounding box of our route
// so we can easily zoom in on it.
MKMapPoint northEastP
MKMapPoint southWestP
// create a c array of points.
MKMapPoint* pointArr = malloc(sizeof(CLLocationCoordinate2D) * locations.count);
for(int idx = 0; idx & locations. idx++)
// break the string down even further to latitude and longitude fields.
NSString* currentPointString = [locations objectAtIndex:idx];
NSArray* latLonArr = [currentPointString componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@&,&]];
CLLocationDegrees latitude
= [[latLonArr objectAtIndex:0] doubleValue];
CLLocationDegrees longitude = [[latLonArr objectAtIndex:1] doubleValue];
CLLocationCoordinate2D coordinate = CLLocationCoordinate2DMake(latitude, longitude);
MKMapPoint point = MKMapPointForCoordinate(coordinate);
if (idx == 0) {
northEastPoint =
southWestPoint =
if (point.x & northEastPoint.x)
northEastPoint.x = point.x;
if(point.y & northEastPoint.y)
northEastPoint.y = point.y;
if (point.x & southWestPoint.x)
southWestPoint.x = point.x;
if (point.y & southWestPoint.y)
southWestPoint.y = point.y;
pointArr[idx] =
self.routeLine = [MKPolyline polylineWithPoints:pointArr count:locations.count];
_routeRect = MKMapRectMake(southWestPoint.x, southWestPoint.y, northEastPoint.x - southWestPoint.x, northEastPoint.y - southWestPoint.y);
free(pointArr);
这样我们就将我们运行得轨迹绘制google地图上面了。
&&& 如果你想使用其他的地图,比如百度地图,其实也很方便。可以将百度地图放置到UIWebView中间,通过用js去绘制轨迹。
总结:这篇文章我们介绍了一种常见的技术实现:在地图上绘制出你运行的轨迹。
参考知识库
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:289901次
积分:3612
积分:3612
排名:第7063名
原创:59篇
转载:101篇
评论:22条
(45)(68)(1)(5)(3)(11)(4)(3)(20)请问用OpenLayers 在地图上画简单的轨迹怎么画呢! - ITeye问答
不需要多复杂!
就是根据传过来的一组坐标,在地图上把这几个坐标点连起来,形成一个轨迹!
谢谢了!
//使用OpenLayers.Layer.Vector,map要先建立
var vectors,lineF//存放线路
//线路样式
var style_green = {
strokeColor: "#00FF00",
strokeWidth: 3,
strokeDashstyle: "dashdot",
pointRadius: 6,
pointerEvents: "visiblePainted"
};
//画线图层设置
var layer_style = OpenLayers.Util.extend({}, OpenLayers.Feature.Vector.style['default']);
layer_style.fillOpacity = 0.2;
layer_style.graphicOpacity = 1;
//画线图层
vectors = new OpenLayers.Layer.Vector("Simple Geometry", {style: layer_style});
map.addLayer(vectors);
//一下采用数组型式填充轨迹
var pointList = [];
for(var i=0;i&5;i++){
&&& newPoint = new OpenLayers.Geometry.Point(lon,lan);
&&& pointList.push(newPoint);
}
lineFeature = new OpenLayers.Feature.Vector(new OpenLayers.Geometry.LineString(pointList),null,style_green);
vectors.addFeatures([lineFeature]);
不知道这个可不可以
已解决问题
未解决问题2013年10月 总版技术专家分月排行榜第三
2014年3月 Java大版内专家分月排行榜第一2014年1月 Java大版内专家分月排行榜第一2013年12月 Java大版内专家分月排行榜第一2013年11月 Java大版内专家分月排行榜第一2013年10月 Java大版内专家分月排行榜第一
本帖子已过去太久远了,不再提供回复功能。android 获取GPS经纬度在百度地图上绘制轨迹
实现将一组GPS模块获取的经纬度数据在百度地图上绘制轨迹
1.将经纬度转换成百度地图坐标
* 标准的GPS经纬度坐标直接在地图上绘制会有偏移,这是测绘局和地图商设置的,要转换成百度地图坐标
* @return 百度地图坐标
public GeoPoint gpsToBaidu(String data) {//data格式
nmea标准数据
ddmm.mmmmm,ddmm.mmmm 如,
String[] p = data.split(",");
int lat = (int) (((int) (Float.valueOf(p[0]) / 100) + (100 * (Float//将ddmm.mmmm格式转成dd.ddddd
.valueOf(p[0]) / 100.0 - (int) (Float.valueOf(p[0]) / 100)) / 60.0)) * 1E6);
int lon = (int) (((int) (Float.valueOf(p[1]) / 100) + (100 * (Float
.valueOf(p[1]) / 100.0 - (int) (Float.valueOf(p[1]) / 100)) / 60.0)) * 1E6);
GeoPoint pt = new GeoPoint(lat, lon);
return CoordinateConvert.fromWgs84ToBaidu(pt);//转成百度坐标
2.在地图上绘制轨迹(已设置好地图)
* 绘制点线
public void addCustomElementsDemo(String[] data) {
GraphicsOverlay graphicsOverlay = new GraphicsOverlay(mMapView);
mMapView.getOverlays().add(graphicsOverlay);
// 添加折线
graphicsOverlay.setData(drawLine(data));//轨迹
graphicsOverlay.setData(drawPoint(data[0]));//起点
graphicsOverlay.setData(drawPoint(data[count - 1]));//终点
// 执行地图刷新使生效
mMapView.refresh();
* 绘制单点,该点状态不随地图状态变化而变化
* @return 点对象
public Graphic drawPoint(String data) {
GeoPoint pt1 = gpsToBaidu(data);
Geometry pointGeometry = new Geometry();
// 设置坐标
pointGeometry.setPoint(pt1, 10);
// 设定样式
Symbol pointSymbol = new Symbol();
Symbol.Color pointColor = pointSymbol.new Color();
pointColor.red = 0;
pointColor.green = 126;
pointColor.blue = 255;
pointColor.alpha = 255;
pointSymbol.setPointSymbol(pointColor);
// 生成Graphic对象
Graphic pointGraphic = new Graphic(pointGeometry, pointSymbol);
return pointG
* 绘制折线,该折线状态随地图状态变化
* @return 折线对象
public Graphic drawLine(String[] data) {
Geometry lineGeometry = new Geometry();
// 设定折线点坐标
GeoPoint[] linePoints = new GeoPoint[count];
for (int i = 0; i < i++) {
linePoints[i] = gpsToBaidu(data[i]);
lineGeometry.setPolyLine(linePoints);
// 设定样式
Symbol lineSymbol = new Symbol();
Symbol.Color lineColor = lineSymbol.new Color();
lineColor.red = 33;
lineColor.green = 99;
lineColor.blue = 255;
lineColor.alpha = 255;
lineSymbol.setLineSymbol(lineColor, 10);
// 生成Graphic对象
Graphic lineGraphic = new Graphic(lineGeometry, lineSymbol);
return lineG
(window.slotbydup=window.slotbydup || []).push({
id: '2467140',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467141',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467142',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467143',
container: s,
size: '1000,90',
display: 'inlay-fix'
(window.slotbydup=window.slotbydup || []).push({
id: '2467148',
container: s,
size: '1000,90',
display: 'inlay-fix'

我要回帖

更多关于 echarts地图上标数字 的文章

 

随机推荐