I
I
Igness_Music2016-12-13 08:14:42
JavaScript
Igness_Music, 2016-12-13 08:14:42

How to center a Yandex map using coordinates from a geolocator?

Tell me how, having received an object through the geolocator, I can take the coordinates for the center of the map itself. Suppose a request to a geolocator returns:

["metaDataProperty"]=>
  array(1) {
    ["GeocoderMetaData"]=>
    array(5) {
      ["kind"]=>
      string(5) "house"
      ["text"]=>
      string(117) "Россия, Свердловская область, Екатеринбург, улица Белинского, 222"
      ["precision"]=>
      string(5) "exact"
      ["AddressDetails"]=>
      array(1) {
        ["Country"]=>
        array(4) {
          ["AddressLine"]=>
          string(103) "Свердловская область, Екатеринбург, улица Белинского, 222"
          ["CountryNameCode"]=>
          string(2) "RU"
          ["CountryName"]=>
          string(12) "Россия"
          ["AdministrativeArea"]=>
          array(2) {
            ["AdministrativeAreaName"]=>
            string(39) "Свердловская область"
            ["SubAdministrativeArea"]=>
            array(2) {
              ["SubAdministrativeAreaName"]=>
              string(85) "муниципальное образование Город Екатеринбург"
              ["Locality"]=>
              array(2) {
                ["LocalityName"]=>
                string(24) "Екатеринбург"
                ["Thoroughfare"]=>
                array(2) {
                  ["ThoroughfareName"]=>
                  string(31) "улица Белинского"
                  ["Premise"]=>
                  array(1) {
                    ["PremiseNumber"]=>
                    string(3) "222"
                  }
                }
              }
            }
          }
        }
      }
      ["id"]=>
      string(8) "56068469"
    }
  }
  ["description"]=>
  string(79) "Екатеринбург, Свердловская область, Россия"
  ["name"]=>
  string(36) "улица Белинского, 222"
  ["boundedBy"]=>
  array(1) {
    ["Envelope"]=>
    array(2) {
      ["lowerCorner"]=>
      string(19) "60.625394 56.797763"
      ["upperCorner"]=>
      string(19) "60.633605 56.802268"
    }
  }
  ["Point"]=>
  array(1) {
    ["pos"]=>
    string(19) "60.629499 56.800015"
  }
}

As far as I understand - Point - this is the coordinates of the point on the map. But if you create a map with these coordinates in this way:
ymaps.ready(function () {
            var myMap = new ymaps.Map("myMap", {
                center: 60.629499,56.800015,
                zoom: 10,
                controls: []
            });
        });

Then the map is not centered at the given address, who knows what the problem is?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Igness_Music, 2016-12-13
@Igness_Music

Problem solved. Yandex geolocator gives the result in one format, but it needs to be entered on the map in another. Therefore, you need to swap the latitude and longitude and everything will work correctly.

S
Sharov Dmitry, 2016-12-13
@vlom88

myMap.setCenter([60.629499,56.800015], 10);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question