简介

新冠医院安排

简单思路

用模拟退火生成序列,用动态规划生成发车次序。

code

main.py

#coding=utf-8
from solution import solution
from draw import draw
import time
import winsound


def main1():
    solve = solution()
    # 因为 xlsx2 文件可以用来解决问题1,2,3所以直接都读取了
    solve.readPointFromFile('D:/code/数学建模/模型2/各点之间的距离.xlsx')
    start = time.clock()
    solve.setProposal(0.5, 0.5)
    xmin, drx, dry = solve.solutionForSubjectOne()
    drawObj = draw()
    drawObj.drawY(drx, dry)
    elapsed = (time.clock() - start)
    print('route', xmin)
    print("Time used:", elapsed)
def submain1():
    result = [10, 10, 10, 10, 10, 8, 8, 8, 8, 8, 11, 11, 11, 11, 11, 6, 6, 6, 6, 8, 10, 10, 10, 10, 4, 4, 4, 4, 4, 6, 6, 6, 6, 10, 10, 10, 10, 10, 9, 9, 9, 9, 7, 4, 4, 4, 4, 4, 2, 2, 2, 2, 3, 3, 3, 3, 3, 7, 7, 7, 7, 7, 1, 1, 11, 11, 11, 5, 5, 5, 5, 5, 7, 7, 7, 7, 7, 1, 1, 1, 1, 1, 5, 5, 5, 5, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 2, 2, 3, 3]
    solve = solution()
    solve.readPointFromFile('D:/code/数学建模/模型2/各点之间的距离.xlsx')
    solve.decRouter(result, '校验结果_2020_08_14_20_23_44.xls')

def main2():
    solve = solution()
    solve.readPointFromFile('D:/code/数学建模/模型2/各点之间的距离.xlsx')
    solve.readHospitalFormFile('D:/code/数学建模/模型2/各点之间的距离.xlsx')

if __name__ == "__main__":
    main2()
    # main1()
    winsound.Beep(300, 100)

node.py

#coding=utf-8
class node:
    def __init__(self, name, x, y, need):
        self.name = name
        self.x = float(x)
        self.y = float(y)
        self.need = int(need)

    def getName(self):
        return self.name

    def getX(self):
        return self.x

    def getY(self):
        return self.y

    def getNeed(self):
        return self.need

    def pp(self):
        print(self.name, self.x, self.y, self.need)


if __name__ == '__main__':
    n = node()

solution.py

#coding=utf-8
import xlrd
import sys
from node import node
from utils import haversine
import numpy as np
import math
import matplotlib.pyplot as plt
import random
import xlwt
import time
class solution:
    '''
    暂时先不考虑约束吧
    '''
    def __init__(self):
        self.nodes = [] # 0 是调配中心
        self.speed = 40 # 10 km/h
        self.timeCoef = 1 # 权重越大  惩罚系数越大
        self.moneyCoef = 1
        self.graph = []
        self.resultBak = []

        self.hosNodes = [] # 医院节点

    def readPointFromFile(self, filename):
        data = xlrd.open_workbook(filename)
        table = data.sheet_by_name('Sheet1')
        name = table.name
        rowNum = table.nrows
        colNum = table.ncols
        print(name, rowNum, colNum)

        for i in range(13):
            if (i == 0 ):
                continue
            tmp = []
            for j in range(4):
                tmp.append(table.cell(i, j).value)
            n = node(tmp[0], tmp[1], tmp[2], tmp[3])
            self.nodes.append(n)
        self.graph = np.zeros((len(self.nodes), len(self.nodes)), dtype=float)
        for i in range(len(self.nodes)):
            for j in range(len(self.nodes)):
                self.graph[i][j] = haversine(self.nodes[i].getX(), self.nodes[i].getY(), self.nodes[j].getX(), self.nodes[j].getY())

        self.wr(self.graph, self.nodes)
        for i in range(len(self.nodes)):
            self.nodes[i].pp()

    def readHospitalFormFile(self, filename):
        data = xlrd.open_workbook(filename)
        table = data.sheet_by_name('Sheet3')
        name = table.name
        rowNum = table.nrows
        colNum = table.ncols
        print(name, rowNum, colNum)

        for i in range(rowNum):
            if (i == 0):
                continue
            tmp = []
            for j in range(4):
                tmp.append(table.cell(i, j).value)
            n = node(tmp[0], tmp[1], tmp[2], tmp[3])
            self.hosNodes.append(n)
        for i in range(len(self.hosNodes)):
            self.hosNodes[i].pp()

    def initX(self):
        x = []
        for i in range(1, len(self.nodes)):
            tmp = [i] * self.nodes[i].getNeed()
            x = x + tmp
        print('初始路线', x)
        random.shuffle(x)
        print('初始路线', x)
        return x

    def genNewResult(self, res):
        '''
        res 就是 X 的值 T 温度越高产生翻转的概率越大 oldT 原本最大温度
        '''
        r = res.copy()
        x = np.random.uniform(low= 0 , high= 1)
        if x >= 0 and x < 0.4: # 使用交换法生成新的路径
            # print('交换')
            c1 = random.randint(0, len(r)-1)
            c2 = random.randint(0, len(r)-1)
            tmp = r[c1]
            r[c1] = r[c2]
            r[c2] = tmp
        elif  x >= 0.4 and x < 0.7: # 使用移动序列产生新路径
            # print('移动')
            c1 = random.randint(0, len(r) - 1)
            c2 = random.randint(0, len(r) - 1)
            c3 = random.randint(0, len(r) - 1)
            tmp = [c1, c2, c3]
            tmp.sort()
            c1 = tmp[0]
            c2 = tmp[1]
            c3 = tmp[2]
            tmp1 = r[0:c1]
            tmp2 = r[c1:c2]
            tmp3 = r[c2:c3]
            tmp4 = r[c3:]
            r = tmp1 + tmp3 + tmp2 + tmp4
        else:
            # print('倒置')
            c1 = random.randint(0, len(r) - 1)
            c2 = random.randint(0, len(r) - 1)
            if c1 > c2:
                tmp = c1
                c1 = c2
                c2 = tmp
            tmp1 = r[0:c1]
            tmp2 = r[c1:c2]
            tmp3 = r[c2:]
            tmp2.reverse()
            r = tmp1 + tmp2 + tmp3
        return r

    def wr(self, graph, myNodes):
        # 将电池电量输入到excel文件
        workbook = xlwt.Workbook(encoding='utf-8')
        # 创建一个worksheet
        worksheet = workbook.add_sheet('My Worksheet')

        # 写入excel
        # 参数对应 行, 列, 值
        for i in range(len(myNodes)):
            for j in range(len(myNodes)):
                worksheet.write(i, j, graph[i][j])
        # 保存
        workbook.save('距离矩阵.xls')

    def wr1(self, n, filename): # 二维数组校验
        # 将电池电量输入到excel文件
        workbook = xlwt.Workbook(encoding='utf-8')
        # 创建一个worksheet
        worksheet = workbook.add_sheet('My Worksheet')

        # 写入excel
        # 参数对应 行, 列, 值
        for i in range(len(n)):
            for j in range(len(n[0])):
                worksheet.write(i, j, n[i][j])
        # 保存
        workbook.save(filename)

    def solutionForSubjectOne(self):
        T = 1000  # initiate temperature
        # 初始化所有分布
        x = self.initX()
        k = 200
        y = sys.maxsize  # 初始y值
        xmin = []  # 记录数据值
        ymin = sys.maxsize
        # 温度衰减系数
        a = 0.95
        # 绘图
        drawX = [i for i in range(200)]
        drawY = []
        n = 200
        while n > 0:
            n-=1
            for i in range(k):
                y = self.aimFunction1(x)
                # generate a new x in the neighboorhood of x by transform function ()
                xNew = self.genNewResult(x)
                yNew = self.aimFunction1(xNew)
                if (yNew <= y):
                    x = xNew.copy()
                    y = yNew
                    if (yNew < ymin):
                        xmin = x.copy()
                        ymin = yNew
                else:
                    p = math.exp(-(yNew - y) / T)
                    r = np.random.uniform(low=0, high=1)
                    if (r < p):
                        x = xNew.copy()
                        y = yNew
            drawY.append(y)
            T = T * a
        print('直接输出', x, self.aimFunction1(x))
        print('记录最小数值', xmin, self.aimFunction1(xmin, shouOut=True))
        return xmin, drawX, drawY

    def aimFunction1(self, x, shouOut = False):
        # start = time.clock()
        rlt, opt = self.dpOpt(x)
        #elapsed = (time.clock() - start)
        #print("Time used:", elapsed)
        if shouOut:
            self.wr1(opt, '校验结果_' + self.randString() + '.xls')
        return rlt
    def randString(self):
        now = int(time.time())
        timeArray = time.localtime(now)
        otherStyleTime = time.strftime("%Y_%m_%d_%H_%M_%S", timeArray)
        return otherStyleTime
    def dpOpt(self, x):
        opt = np.zeros((len(x) + 1, 6), dtype=float)
        opt[0][0] = 0 # 记录上一个最高值
        opt[0][1] = self.calValue(x[:1])
        opt[0][2] = self.calValue(x[:2])
        opt[0][3] = self.calValue(x[:3])
        opt[0][4] = self.calValue(x[:4])
        opt[0][5] = self.calValue(x[:5])
        bak = x.copy()
        bak.append(0)
        bak.append(0)
        bak.append(0)
        bak.append(0)
        bak.append(0)
        bak.append(0) # opt[100][0] 就是最小值
        for i in range(1, len(x) + 1):
            for j in range(0, 6):
                if j == 0:
                    if i == 1:
                        opt[i][0] = opt[i-1][1]
                    elif i == 2:
                        opt[i][0] = min(opt[i - 1][1], opt[i-2][2])
                    elif i == 3:
                        opt[i][0] = min(opt[i - 1][1], opt[i - 2][2], opt[i - 3][3])
                    elif i == 4:
                        opt[i][0] = min(opt[i - 1][1], opt[i - 2][2], opt[i - 3][3], opt[i - 4][4])
                    else:
                        opt[i][0] = min(opt[i - 1][1], opt[i - 2][2], opt[i - 3][3], opt[i - 4][4], opt[i - 5][5])
                else:
                    opt[i][j] = opt[i][0] + self.calValue(bak[i:i+j])

        return opt[len(x)][0], opt

    def decRouter(self, result, filename):
        data = xlrd.open_workbook(filename)
        table = data.sheet_by_name('My Worksheet')
        name = table.name
        rowNum = table.nrows
        colNum = table.ncols
        print(name, rowNum, colNum)
        route = []
        for i in range(rowNum):
            tmp = []
            for j in range(colNum):
                tmp.append(float(table.cell(i, j).value))
            route.append(tmp)
        # 表格恢复 在从尾部开始遍历
        carTimes = [] # 车次
        r = len(route)
        while r >= 7:
            thisMax = route[r - 1][0]
            # print(thisMax, route[ r - 2 ][1], route[ r - 3][2], route[ r - 4][3], route[r - 5][4], route[r - 6][5])
            if math.fabs(thisMax - route[ r - 2 ][1]) < 0.0001:
                tmp = result[r-2 : r - 2 + 1]
                carTimes.insert(0, tmp)
                r -= 1
            elif math.fabs(thisMax - route[ r - 3][2]) < 0.0001:
                tmp = result[r - 3: r - 3 + 2]
                carTimes.insert(0, tmp)
                r -= 2
            elif math.fabs(thisMax - route[ r - 4][3]) < 0.0001:
                tmp = result[r - 4: r - 4 + 3]
                carTimes.insert(0, tmp)
                r -= 3
            elif math.fabs(thisMax - route[r - 5][4]) < 0.0001:
                tmp = result[ r- 5: r - 5 + 4]
                carTimes.insert(0, tmp)
                r -= 4
            elif math.fabs(thisMax - route[r - 6][5]) < 0.0001:
                tmp = result[ r - 6: r - 6 + 5]
                carTimes.insert(0, tmp)
                r -= 5
        carTimes.insert(0, result[0:r - 2])
        for i in range(len(carTimes)):
            ss = carTimes[i].copy()
            ss = list(set(ss))
            sss = np.zeros(len(ss))
            for j in range(len(carTimes[i])):
                for k in range(len(ss)):
                    if ss[k] == carTimes[i][j]:
                        sss[k] += 1
            print('第 ' + str(i) + ' 次发车:', end='')
            for t in range(len(ss)):
                print(self.nodes[ss[t]].getName(),'发送了',sss[t],'吨',end=' ')
            print()
        allTime = 0
        allMoney = 0
        for i in range(len(carTimes)):
            time, money = self.calValue1(carTimes[i])
            allTime += time
            allMoney += money
        print('time', allTime, 'money', allMoney)





    def recOpt(self, x, index):
        leng = len(x)
        if leng == 0:
            return 0
        val = []
        for i in range(5):
            val.append(0)

        if leng > 1: # 返回汽车运送这一个节点之后返回的时间和
            val[0] = self.calValue(x[:1]) + self.recOpt(x[1:], index=1+index)
        elif leng == 1:
            val[0] = self.calValue(x)

        if leng > 2:
            val[1] = self.calValue(x[:2]) + self.recOpt(x[2:], index=1+index)
        elif leng == 2:
            val[1] = self.calValue(x)

        if leng > 3:
            val[2] = self.calValue(x[:3]) + self.recOpt(x[3:], index=1+index)
        elif leng == 3:
            val[2] = self.calValue(x)

        if leng > 4:
            val[3] = self.calValue(x[:4]) + self.recOpt(x[4:], index=1+index)
        elif leng == 4:
            val[3] = self.calValue(x)

        if leng > 5:
            val[4] = self.calValue(x[:5]) + self.recOpt(x[5:], index=1+index)
        elif leng == 5:
            val[4] = self.calValue(x)

        minValue = sys.maxsize
        minPosition = 0
        for i in range(5):
            if(minValue >= val[i]):
                minValue = val[i]
                minPosition = i
        if (index == 1):
            print(minPosition)
        return minValue


    def calValue(self, x):
        # 假定最后都回到发车点杭州市卫健委
        goods = len(x) # 货物 吨
        res = [0] + x

        allDistance = 0
        allMoney = 0
        for i in range(len(res)):
            lastPoint = res[i]
            if (i + 1 >= len(res)):
                nextPoint = res[0]
            else:
                nextPoint = res[i + 1]
            x1 = self.nodes[lastPoint].getX()
            y1 = self.nodes[lastPoint].getY()
            x2 = self.nodes[nextPoint].getX()
            y2 = self.nodes[nextPoint].getY()
            distance = haversine(x1, y1, x2, y2)
            allDistance += distance
            allMoney += (20 + goods * 10) * distance
            goods -= 1
        time = allDistance / self.speed * 3600
        value = time * self.timeCoef + allMoney * self.moneyCoef
        return value

    def calValue1(self, x):
        # 假定最后都回到发车点杭州市卫健委
        goods = len(x) # 货物 吨
        res = [0] + x

        allDistance = 0
        allMoney = 0
        for i in range(len(res)):
            lastPoint = res[i]
            if (i + 1 >= len(res)):
                nextPoint = res[0]
            else:
                nextPoint = res[i + 1]
            x1 = self.nodes[lastPoint].getX()
            y1 = self.nodes[lastPoint].getY()
            x2 = self.nodes[nextPoint].getX()
            y2 = self.nodes[nextPoint].getY()
            distance = haversine(x1, y1, x2, y2)
            allDistance += distance
            allMoney += (20 + goods * 10) * distance
            goods -= 1
        time = allDistance / self.speed * 3600
        value = time * self.timeCoef + allMoney * self.moneyCoef
        return time, allMoney

    def setProposal(self, timeCoef, moneyCoef):
        self.timeCoef = timeCoef
        self.moneyCoef = moneyCoef

    def solutionForTow(self):
        pass

    def genDistanceTable(self):
        # 将电池电量输入到excel文件
        workbook = xlwt.Workbook(encoding='utf-8')
        # 创建一个worksheet
        worksheet = workbook.add_sheet('sheet1')
        
        # 写入excel
        # 参数对应 行, 列, 值
        for i in range(len(n)):
            for j in range(len(n[0])):
                worksheet.write(i, j, n[i][j])
        # 保存
        workbook.save(filename)

utils.py

#coding=utf-8
from math import radians, cos, sin, asin, sqrt, acos
import math
def haversine(lon1, lat1, lon2, lat2):  # 经度1,纬度1,经度2,纬度2 (十进制度数)
    """
    https://blog.csdn.net/vernice/article/details/46581361
    Calculate the great circle distance between two points
    on the earth (specified in decimal degrees)
    """
    # 将十进制度数转化为弧度
    # lon1 = lon1 / 180.0 * math.pi
    # lat1 = lat1 / 180.0 * math.pi
    # lon2 = lon2 / 180.0 * math.pi
    # lat2 = lat2 / 180.0 * math.pi
    lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
    # haversine公式
    dlon = lon2 - lon1
    dlat = lat2 - lat1
    a = math.sin(dlat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(dlon / 2) ** 2
    c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a))
    r = 6373  # 地球平均半径,单位为km
    return c * r # 返回km

html 生成 地图图标

<!DOCTYPE html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
	<style type="text/css">
	body, html,#allmap {width: 100%;height: 100%;overflow: hidden;margin:0;font-family:"微软雅黑";}
	</style>
	<script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak=G8U5jxfG5l373ytOYzYYy0l1EY7ceO9P"></script>
	<title>地图展示</title>
</head>
<body>
	<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
	// 百度地图API功能
	var map = new BMap.Map("allmap");    // 创建Map实例
	map.centerAndZoom("杭州", 11);  // 初始化地图,设置中心点坐标和地图级别
	//添加地图类型控件
	map.addControl(new BMap.MapTypeControl({
		mapTypes:[
            BMAP_NORMAL_MAP,
            BMAP_HYBRID_MAP
        ]}));	  
	map.enableScrollWheelZoom(true);     //开启鼠标滚轮缩放
	var  mapStyle ={ 
        features: ["road", "building","water","land"],//隐藏地图上的poi
        style : "light"  //设置地图风格为高端黑
    }
	map.setMapStyle(mapStyle);

	// var local = new BMap.LocalSearch(map, {
	// 	renderOptions:{map: map}
	// });
	// local.search("景点");
	// pointLocation();


		var locations = [
			'杭州市疾病预防控制中心',
			'上城区疾病预防控制中心',
			'下城区疾病预防控制中心',
			'江干区疾病预防控制中心',
			'西湖区疾病预防控制中心',
			'杭州钱塘新区教育与卫生健康系统党群服务中心',
			'滨江区疾病预防控制中心',
			'杭州西湖风景名胜区疾病预防控制中心',
			'萧山区疾病预防控制中心',
			'余杭区疾病预防控制中心',
			'杭州市拱墅区公共卫生中心'
		];
		var myGeo = new BMap.Geocoder();
		// 将地址解析结果显示在地图上,并调整地图视野
		myGeo.getPoint("杭州市疾病预防控制中心", function(point){
			if (point) {
				console.log("杭州市疾病预防控制中心",point)
				map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("杭州市疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")
		myGeo.getPoint("上城区疾病预防控制中心", function(point){
			if (point) {
				console.log("上城区疾病预防控制中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("上城区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")
		myGeo.getPoint("下城区疾病预防控制中心", function(point){
			if (point) {
				console.log("下城区疾病预防控制中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("下城区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")
		myGeo.getPoint("江干区疾病预防控制中心", function(point){
			if (point) {
				console.log("江干区疾病预防控制中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("江干区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")
		myGeo.getPoint("西湖区疾病预防控制中心", function(point){
			if (point) {
				console.log("西湖区疾病预防控制中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("西湖区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")

		local_hz_qtxqjyywsjk = {
			lat : 30.289927,
			lng :120.379635,
			of : "inner"
		}
		map.addOverlay(new BMap.Marker(local_hz_qtxqjyywsjk));
		var opts = {
			position : local_hz_qtxqjyywsjk,    // 指定文本标注所在的地理位置
			offset   : new BMap.Size(30, -30)    //设置文本偏移量
		}
		var label = new BMap.Label("杭州钱塘新区疾控中心", opts);  // 创建文本标注对象
			label.setStyle({
				color : "red",
				fontSize : "12px",
				height : "20px",
				lineHeight : "20px",
				fontFamily:"微软雅黑"
			});
		map.addOverlay(label);
		console.log("杭州钱塘新区教育与卫生健康系统党群服务中心",local_hz_qtxqjyywsjk)

		
		local_hz_center = {
			lat : 30.245155,
			lng :120.209439,
			of : "inner"
		}
		var options = {
            size: BMAP_POINT_SIZE_SMALL,
            shape: BMAP_POINT_SHAPE_STAR,
            color: 'red'
        }
		var pointCollection = new BMap.Marker(local_hz_center, options);
		// var cen = new BMap.Marker(local_hz_center)
		map.addOverlay(pointCollection);
		var opts = {
			position : local_hz_center,    // 指定文本标注所在的地理位置
			offset   : new BMap.Size(30, -30)    //设置文本偏移量
		}
		var label = new BMap.Label("杭州市卫健委", opts);  // 创建文本标注对象
			label.setStyle({
				color : "red",
				fontSize : "12px",
				height : "20px",
				lineHeight : "20px",
				fontFamily:"微软雅黑"
			});
		map.addOverlay(label);
		console.log("杭州市卫生健康委员会",local_hz_center)
		// myGeo.getPoint("杭州钱塘新区教育与卫生健康系统党群服务中心", function(point){
		// 	if (point) {
		// 		console.log("杭州钱塘新区教育与卫生健康系统党群服务中心",point)
		// 		// map.centerAndZoom(point, 16);
		// 		map.addOverlay(new BMap.Marker(point));


		// 		var opts = {
		// 		position : point,    // 指定文本标注所在的地理位置
		// 		offset   : new BMap.Size(30, -30)    //设置文本偏移量
		// 		}
		// 		var label = new BMap.Label("杭州钱塘新区教育与卫生健康系统党群服务中心", opts);  // 创建文本标注对象
		// 			label.setStyle({
		// 				color : "red",
		// 				fontSize : "12px",
		// 				height : "20px",
		// 				lineHeight : "20px",
		// 				fontFamily:"微软雅黑"
		// 			});
		// 		map.addOverlay(label); 
		// 	}else{
		// 		alert("您选择地址没有解析到结果!");
		// 	}
		// }, "杭州市")
		myGeo.getPoint("滨江区疾病预防控制中心", function(point){
			if (point) {
				console.log("滨江区疾病预防控制中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("滨江区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")
		myGeo.getPoint("杭州西湖风景名胜区疾病预防控制中心", function(point){
			if (point) {
				console.log("杭州西湖风景名胜区疾病预防控制中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));


				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -10)    //设置文本偏移量
				}
				var label = new BMap.Label("杭州西湖风景区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")

		myGeo.getPoint("萧山区疾病预防控制中心", function(point){
			if (point) {
				console.log("萧山区疾病预防控制中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("萧山区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")

		myGeo.getPoint("余杭区疾病预防控制中心", function(point){
			if (point) {
				console.log("余杭区疾病预防控制中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("余杭区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")

		myGeo.getPoint("杭州市拱墅区公共卫生中心", function(point){
			if (point) {
				console.log("杭州市拱墅区公共卫生中心",point)
				// map.centerAndZoom(point, 16);
				map.addOverlay(new BMap.Marker(point));

				var opts = {
				position : point,    // 指定文本标注所在的地理位置
				offset   : new BMap.Size(30, -30)    //设置文本偏移量
				}
				var label = new BMap.Label("杭州市拱墅区疾控中心", opts);  // 创建文本标注对象
					label.setStyle({
						color : "red",
						fontSize : "12px",
						height : "20px",
						lineHeight : "20px",
						fontFamily:"微软雅黑"
					});
				map.addOverlay(label); 
			}else{
				alert("您选择地址没有解析到结果!");
			}
		}, "杭州市")


		// var myGeo = new BMap.Geocoder();
		// // 将地址解析结果显示在地图上,并调整地图视野
		// myGeo.getPoint("杭州市疾病预防控制中心", function(point){
		// 	if (point) {
		// 		console.log("杭州市疾病预防控制中心",point)
		// 		map.centerAndZoom(point, 16);
		// 		map.addOverlay(new BMap.Marker(point));
		// 	}else{
		// 		alert("您选择地址没有解析到结果!");
		// 	}
		// }, "杭州市")
</script>
posted on 2020-08-18 19:42  HDU李少帅  阅读(306)  评论(0编辑  收藏  举报