0
Hello, I’m with a map, google maps, that marks positions of various places. In a general way I would like that, when entering the address in the form of my site, the location is marked on the map without having to drag the position on the map, automate the positioning on the map.
<div class="col-md-12">
<script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBUMKHFlfDJ5cOq4ZqnaTtwaV99_zcLUSY&callback=initMap"></script>
<script>
function initMap() {
var myLatLng = { lat: <%= @unit.coordinates[:latitude] %>, lng: <%= @unit.coordinates[:longitude] %> };
var map = new google.maps.Map(document.getElementById('map'), {
center: myLatLng,
scrollwheel: false,
zoom: 15
});
var marker = new google.maps.Marker({
map: map,
position: myLatLng
});
};
</script>
<div id="map" style="width: 100%; height: 200px; margin-bottom: 10px;"></div>
</div>
This map allows you to drag the point to where I want but I want that when entering the address in the form it positions the point on the map referring to the address.
Grateful for the attention!
I have code for it but it’s by coordinates
– Miguel
may help, I can make a coordinate query script and return the address
– Carlos Andre
OK what I have is here: https://jsfiddle.net/tzhgLyz3/ ... In this case you put the name of the zone so that the pin (inserted by the coordinates) gets this description. http://stackoverflow.com/questions/9309251/google-maps-javascript-api-get-gps-coordinates-from-address, http://stackoverflow.com/questions/3652951/google-maps-api-get-coordinates-of-address You can see that it is possible to return the coordinates by the address
– Miguel
Thanks, now I will make a script to get the coordinates of the address and join with this your code.
– Carlos Andre