android百度地图开发--自定义最短路径搜索图层

由于需要,需要在百度地图的基础上实现小范围(例如校园,景区等地)内的详细最短路径导航,百度地图无法实现,因此通过SQLite数据库自行添加地点坐标信息,然后通过Dijkstra算法实现了两地点间的最短路径搜索。

 

直接上代码:

首先是定义的一个节点雷:Side.java

用于存放以及获取节点信息

package com.xjdx.suanfa;

public class Side {
	private int preNode; //前驱节点
	private int nextNode;//后继节点
	private int weight;//权重
	
	public Side(int preNode,int nextNode,int weight){
		this.preNode = preNode;
		this.nextNode = nextNode;
		this.weight = weight;
	}
	
	public int getPreNode(){
		return this.preNode;
	}
	
	public void setPreNode(int preNode){
		this.preNode = preNode;
	}
	
	public int getNextNode(){
		return this.nextNode;
	}
	
	public void setNextNode(int nextNode){
		this.nextNode = nextNode;
	}
	
	public int getWeight(){
		return this.weight;
	}
	
	public void setWeight(int weight){
		this.weight = weight;
	}
	
}

 

然后是一个用于存储以及获取最短路径类:MinShortPath.java

package com.xjdx.suanfa;

import java.util.ArrayList;

public class MinShortPath {
	private ArrayList<Integer> nodeList;//最短路径集
	private int weight;//最短路径
	
	public MinShortPath(int node){
		nodeList = new ArrayList<Integer>();
		nodeList.add(node);
		weight = -1;
	}
	
	public ArrayList<Integer> getNodeList(){
		return nodeList;
	}
	
	public void setNodeList(ArrayList<Integer> nodeList){
		this.nodeList = nodeList;
	}
	
	public void addNode(int node){
		if(nodeList == null){
			nodeList = new ArrayList<Integer>();
		}
		nodeList.add(0,node);
	}
	
	public int getLastNode(){
		int size = nodeList.size();
		return nodeList.get(size-1);
	}
	
	public int getWeight(){
		return weight;
	}
	
	public void setWeight(int weight){
		this.weight = weight;
	}
	
	public void outputPath(){
		outputPath(-1);
	}
	
	public void outputPath(int srcNode){
		String result = "[";
		if(srcNode != -1){
			nodeList.add(srcNode);
		}
		for(int i=0;i<nodeList.size();i++){
			result += "" + nodeList.get(i);
			if(i<nodeList.size()-1){
				result += ",";
			}
		}
		result +="]:"+weight;
		System.out.println(result);
	}
	
	public void addWeight(int w){
		if(weight == -1){
			weight = w;
  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 9
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 9
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值