Answer the question
In order to leave comments, you need to log in
How to get the user's city using the Yandex.Maps API and insert it on the page?
The Yandex.Maps JavaScript API 1.x documentation provides an example of how, based on the IP address, by comparison, determine the user's estimated location and insert a map with a label on the site page.
I plan to add hidden inputs to the application form code:
<div class="response-ip-city">
<input type="hidden" name="ya-city" value=" " >
<input type="hidden" name="ya-country" value=" " >
</div>
<script src="//api-maps.yandex.ru/2.0/?load=package.standard&lang=ru-RU" type="text/javascript"></script>
<script type="text/javascript">
ymaps.ready(init);
function init() {
var geolocation = ymaps.geolocation;
if (geolocation) {
jQuery(function($){
$("input[name='ya-city']").val(geolocation.city);
$("input[name='ya-country']").val(geolocation.country);
});
} else {
console.log('Не удалось установить местоположение');
}
}
</script>
Answer the question
In order to leave comments, you need to log in
1.1 is easier in what sense? In such a ?
There are also simple solutions:
1) Either determine the position using HTML5 Geolocation and find out everything you need using geocoding ;
2) Either use geolocation .
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question