调用高德开放平台-----路径规划API

调用路径规划API的输入与输出源代码展示

1.获取地理编码输入源代码

def geocode(address,city=None,batch=None,sig=None)->dict:
    """获取地理编码"""
    url = 'https://restapi.amap.com/v3/geocode/geo?parameters'
    params={
        'key': key,
        'address':address,
        'city':city,
        'batch':batch,
        'sig':sig,
        'output':'json'
    }
    response = requests.get(url,params=params)
    data = response.json()
    return data
九寨沟 = geocode(address='四川省阿坝藏族羌族自治州九寨沟')
print(九寨沟)
九寨沟地理编码 = 九寨沟['geocodes'][0]['location']
print("九寨沟地理编码:",九寨沟地理编码)

获取地理编码输出源代码

{'status': '1', 'info': 'OK', 'infocode': '10000', 'count': '1', 'geocodes': [{'formatted_address': '四川省阿坝藏族羌族自治州九寨沟县', 'country': '中国', 'province': '四川省', 'citycode': '0837', 'city': '阿坝藏族羌族自治州', 'district': '九寨沟县', 'township': [], 'neighborhood': {'name': [], 'type': []}, 'building': {'name': [], 'type': []}, 'adcode': '513225', 'street': [], 'number': [], 'location': '104.243841,33.252056', 'level': '区县'}]}
九寨沟地理编码: 104.243841,33.252056

2.调用路径规划API输入源代码

def walking(origin,destination,sig=None)->dict:
    url = 'https://restapi.amap.com/v3/direction/walking?parameters'
    params={
        'key':key,
        'origin':origin,
        'destination':destination,
        'output':'json'
    }
    response = requests.get(url,params=params)
    data = response.json()
    return data
九寨沟_location = 九寨沟['geocodes'][0]['location']
九寨沟公共厕所_location = '104.246078,33.242995'
九寨沟_九寨沟公共厕所 = walking(九寨沟_location,九寨沟公共厕所_location)
九寨沟_九寨沟公共厕所

调用路径规划API输出源代码

{'status': '1',
 'info': 'ok',
 'infocode': '10000',
 'count': '1',
 'route': {'origin': '104.243841,33.252056',
  'destination': '104.246078,33.242995',
  'paths': [{'distance': '1272',
    'duration': '1018',
    'steps': [{'instruction': '向东步行115米右转',
      'orientation': '东',
      'road': [],
      'distance': '115',
      'duration': '92',
      'polyline': '104.243854,33.252257;104.244991,33.252196;104.244991,33.252196;104.2451,33.252183',
      'action': '右转',
      'assistant_action': [],
      'walk_type': '0'},
     {'instruction': '沿544国道向南步行455米左转',
      'orientation': '南',
      'road': '544国道',
      'distance': '455',
      'duration': '364',
      'polyline': '104.2451,33.252179;104.244996,33.251259;104.244996,33.251259;104.244935,33.250668;104.244935,33.250668;104.244935,33.250642;104.244935,33.250642;104.244835,33.249796;104.244835,33.249796;104.244714,33.248837;104.244714,33.248837;104.244653,33.248576;104.244553,33.248251;104.244553,33.248251;104.24451,33.248147;104.24451,33.248147;104.244488,33.248095',
      'action': '左转',
      'assistant_action': [],
      'walk_type': '0'},
     {'instruction': '步行28米直行',
      'orientation': [],
      'road': [],
      'distance': '28',
      'duration': '22',
      'polyline': '104.244484,33.24809;104.244757,33.248008',
      'action': '直行',
      'assistant_action': [],
      'walk_type': '0'},
     {'instruction': '步行67米直行',
      'orientation': [],
      'road': [],
      'distance': '67',
      'duration': '54',
      'polyline': '104.244757,33.248003;104.245391,33.247704',
      'action': '直行',
      'assistant_action': [],
      'walk_type': '22'},
     {'instruction': '步行54米右转',
      'orientation': [],
      'road': [],
      'distance': '54',
      'duration': '43',
      'polyline': '104.245391,33.2477;104.245894,33.247461',
      'action': '右转',
      'assistant_action': [],
      'walk_type': '0'},
     {'instruction': '向南步行553米到达目的地',
      'orientation': '南',
      'road': [],
      'distance': '553',
      'duration': '442',
      'polyline': '104.245894,33.247457;104.245829,33.247418;104.245629,33.247209;104.244813,33.246324;104.244731,33.246128;104.244701,33.245968;104.244701,33.24582;104.244718,33.245703;104.244796,33.245503;104.245252,33.244553;104.245252,33.244553;104.245369,33.244327;104.245551,33.244019;104.245773,33.243698;104.245955,33.243459;104.246267,33.243125',
      'action': [],
      'assistant_action': '到达目的地',
      'walk_type': '0'}]}]}}

你可能感兴趣的:(调用高德开放平台-----路径规划API)