从JSON解析经纬度

问题描述 投票:0回答:1

我有一个lat和long的JSON文件,格式错误,无法为地图标记调用位置{lat,lng}。

我正在尝试执行getJSON,并针对每个不正确的经纬度和纬度,将其发送到将其解析为正确格式并向我的地图添加标记的函数。

我虽然没有运气。它像“ latLang”:“ 27.8247427:-82.75040159999999”

这里是指向JSON的链接以供参考。 JSON

这是我的代码。

$(document).ready(function() {
    $.getJSON("http://cs1.utm.edu/~bbradley/map1/customers1.json", function(data) {
      const markers = data.map(({
        latLang
      }) => new google.maps.Marker({
        map: myMap,
        position: new google.maps.LatLng(parseGeo(latLang))
      }));
    });
  });

  const parseGeo = str => { // this is to parse it into the right format
    const [lat, lng] = str.split(':').map(value => parseFloat(value, 10));
    return {
      lat,
      lng
    };
  }

从JSON执行

[{
        "name": "Carole McKenzie",
        "address": "5720 80TH ST NORTH UNIT 310",
        "cityStateZip": "ST PETERSBURG, Florida 33709",
        "latLang": "27.8247427:-82.75040159999999",
        "image": "./people/MTI4MTYuanBn.jpg"
    },
    {
        "name": "Matt Russell",
        "address": "1211 Miller Place Dr",
        "cityStateZip": "Bryant, Arkansas 72022-2389",
        "latLang": "34.606806:-92.5042948",
        "image": "./people/MTQ3OTUuanBn.jpg"
    },
    {
        "name": "George Thrapp",
        "address": "2906 Haddington Court",
        "cityStateZip": "North Chesterfield, Virginia 23224-5716",
        "latLang": "37.466937:-77.5075449",
        "image": "./people/MTk3NTkuanBn.jpg"
    },
javascript json geocoding
1个回答
0
投票

乍看之下,我认为您遇到的问题是[[might

© www.soinside.com 2019 - 2024. All rights reserved.