kazarin0v
@kazarin0v
Разработчик сайтов WordPress

Как конвертировать GoogleMaps координаты в 2GIS координаты и наоборот?

Это одни и те же координаты, полученные методом "map.getBounds", но форматы разные. Мне нужно использовать GoogleMaps координаты в 2GIS и наоборот.

Имеется ввиду что google-south отличается от 2gis-south
"south": 43.106491921792255, | "southWest": [ 43.256449960663694,

Соответственно смысл в том чтобы конвертировать координаты GoogleMaps в 2GIS - тоесть сейчас цифры разные
Это 43.256449960663694 конвертировать в это 43.106491921792255


GoogleMaps:

{
    "south": 43.106491921792255,
    "west": 76.71745650634767,
    "north": 43.4065384633472,
    "east": 77.13974349365236
}

2GIS:

{
    "northEast": [
        43.25695003829279,
        76.92894332280319,
    ],
    "southWest": [
        43.256449960663694,
        76.92825667730312,
    ]
}
  • Вопрос задан
  • 110 просмотров
Решения вопроса 2
Aetae
@Aetae Куратор тега JavaScript
Тлен
Преобразует любые на входе в универсальные:
class CompatibleBounds {
  northEast = [0, 0];
  southWest = [0, 0];

  constructor(bounds) {
    Object.assign(this, bounds);
  }

  static new(bounds) {
    return new this(bounds);
  }

  get south(){ return this.southWest[1] }
  get west(){ return this.southWest[0] }
  get north(){ return this.northEast[1] }
  get east(){ return this.northEast[0] }
  set south(value){ this.southWest[1] = value }
  set west(value){ this.southWest[0] = value }
  set north(value){ this.northEast[1] = value }
  set east(value){ this.northEast[0] = value }
}

const compatibleBounds = CompatibleBounds.new({
  "south": 43.106491921792255,
  "west": 76.71745650634767,
  "north": 43.4065384633472,
  "east": 77.13974349365236
});
// или
const compatibleBounds = CompatibleBounds.new({
  "northEast": [
    76.92894332280319,
    43.25695003829279
  ],
  "southWest": [
    76.92825667730312,
    43.256449960663694
  ]
});

// на выходе универсальный динамический объект:
compatibleBounds.southWest = [1, 2];
console.log(compatibleBounds.south); // 2

compatibleBounds.south = 3
console.log(compatibleBounds.southWest); // [1, 3]

Но если действие требуется одноразовые, то лучше руками перегнать один раз.:)
Ответ написан
Комментировать
const gmExample = {
    "south": 43.106491921792255,
    "west": 76.71745650634767,
    "north": 43.4065384633472,
    "east": 77.13974349365236
};

const dgExample= {
    "northEast": [
        76.92894332280319,
        43.25695003829279
    ],
    "southWest": [
        76.92825667730312,
        43.256449960663694
    ]
};

const gm = {
  "south": dgExample.southWest[1],
    "west": dgExample.southWest[0],
    "north": dgExample.northEast[1],
    "east": dgExample.northEast[0]
};
const dg = {
    "northEast": [
        gmExample.east,
        gmExample.north
    ],
    "southWest": [
        gmExample.west,
        gmExample.south
    ]

};
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы