Skip to content

Instantly share code, notes, and snippets.

@mir4a
Created June 12, 2013 10:41
Show Gist options
  • Save mir4a/5764317 to your computer and use it in GitHub Desktop.
Save mir4a/5764317 to your computer and use it in GitHub Desktop.
Поиск города по ширине и долготе (из navigator.geolocation) через гугл-карты. <script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
geocoder = new google.maps.Geocoder();
function codeLatLng(latlng) {
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var city = results[1]["address_components"][2]["short_name"];
var setPhone;
switch (city) {
case "Донецк":
setPhone = "Donetsk";
break;
case "Макеевка":
setPhone = "Makeevka";
break;
case "Мариуполь":
setPhone = "Mariupol";
break;
case "Краматорск":
setPhone = "Kramatorsk";
break;
default:
setPhone = "Donetsk";
break;
}
$('.b-phones__item[data-filial="'+setPhone+'"]').show().siblings().hide();
// console.log(setPhone);
// console.log(results[1]);
// console.info(city);
}
}
});
}
(function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
})();
function showPosition(position) {
var _latlng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
codeLatLng(_latlng);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment