基于地图的短信追踪小练习(7)经纬度的设置与显示

前面我们在地图显示界面点击一个按钮,就可以发送短信,收到短信的应用会回复一条本身经纬度的短信。


现在我们要根据收到的经纬度信息来设置并显示。


1.处理经纬度信息,设置图标。

->利用java的api提供的字符串处理的函数

if(fullMessage.trim().contains("/"))
				{
						String[] s = fullMessage.split("/");
						LatLng point = new LatLng(Double.valueOf(s[0])+0.002,Double.valueOf(s[1])+0.002);
						//LatLng point = new LatLng(location.getLatitude()+0.02, location.getLongitude()+0.02);  
						BitmapDescriptor bitmap = BitmapDescriptorFactory.fromResource(R.drawable.icon_marker);  
						OverlayOptions option = new MarkerOptions().position(point).icon(bitmap);  
						mBaiduMap.addOverlay(option);
}

2.我们要计算距离并在图标上显示,并显示图标本身的经纬度

LatLng middlepoint = new LatLng(location.getLatitude(), location.getLongitude());
						double d = DistanceUtil.getDistance(point,middlepoint);
						List<LatLng> points = new ArrayList<LatLng>();
						points.add(middlepoint);
						points.add(point);
						OverlayOptions ooPolyline = new PolylineOptions().width(10).color(0xAAAA0000).points(points); 
						
						
						 LatLng lat = new LatLng((location.getLatitude()+Double.valueOf(s[0]))/2, (location.getLongitude()+Double.valueOf(s[1]))/2);

							OverlayOptions o1 = new TextOptions()
							.position(point)
							.text(s[0]+s[1]+"\n"+address).fontSize(35)
							.fontColor(0xAAAA0000);                          //flag
							
						OverlayOptions o2 = new TextOptions()
						.position(lat)
						.text("距离"+d).fontSize(35);
	/**/							
						mBaiduMap.addOverlay(o1);
						mBaiduMap.addOverlay(o2);
						 mBaiduMap.addOverlay(ooPolyline);  

这上面代码本来一直出错,提示接收不到短信,于是乎一步步注释排查,找到问题出在//flag那一句

再不断的注释发现,本来的).fontColor(getResources().getColor(R.color.red))这一个分句出错,要么去掉,要么直接传入十六进制。


3.给图标设置点击事件


//对 marker 添加点击相应事件
		mBaiduMap.setOnMarkerClickListener(new OnMarkerClickListener() {
			
			@Override
			public boolean onMarkerClick(Marker arg0) {
		
			}
		});


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值