V
V
vasilseodor2015-05-07 14:06:20
JavaScript
vasilseodor, 2015-05-07 14:06:20

How to make the center of the map depending on the region?

There is a google map. It has a lot of marks on it. (new google.maps.LatLng). There is also a condition that works through the Yandex Maps API of the form:

else if (ymaps.geolocation.city == "Город") {
  jQuery(".email").html("ящик@домен");}

The essence of which. What if the user's region matches the region in the condition, then the email is spoofed.
Centering the map looks like this
var mapOptions={zoom:6,center:new google.maps.LatLng(координата,координата)}

Is it possible to make it so that the centering takes place on a defined region of the Yamaps API?

That is, something like this: (to set the latitude and longitude in the conditions)
else if (ymaps.geolocation.city == "Город") {
  jQuery(".email").html("ящик@домен");
//здесь как происваивать переменной координаты и центрировать по ним;}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Petrov, 2015-05-07
@Petroveg

ymaps.ready(function () {
  ymaps.geolocation.get({
    provider: 'yandex'
  }).then(function (result) {
    var coords = result.geoObjects.get(0).geometry.getCoordinates();
    /*map — ссылка на карту Google*/
    map.setCenter(new google.maps.LatLng(coords[0], coords[1]));
  });
});

Example

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question