D
D
Dmitry2017-07-16 09:54:28
JavaScript
Dmitry, 2017-07-16 09:54:28

How to display a Google Map marker in the wrong address. what about coordinates?

Good morning. There is a code:

var geocoder;
var map;
var query = new Array('Набережные Челны, ул. Ш. Усманова 56а','Нижнекамск, ул Баки Урманче 15','Россия, Республика Татарстан, Набережные Челны, проспект Мира, 50/15');
var idArr = new Array('mp0','mp1','mp2');

function initialize() {
  geocoder = new google.maps.Geocoder();
  var mapOptions = {
    zoom: 15
  }
  map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
  codeAddress();
}
 
function codeAddress() {
    for (var i = 0; i < query.length; i++) {
        var address = query[i];
    
        geocoder.geocode({
                'address': address
            }, function(k) {
                return function(results, status) {
                    if (status == google.maps.GeocoderStatus.OK) {
                        var a = document.getElementById(idArr[k]);
                        a.onclick = function() {
                            map.setZoom(17);
                            map.setCenter(results[0].geometry.location);
                        }
                        map.setCenter(results[0].geometry.location);
            
                        var marker = new google.maps.Marker({
                            map: map,
                            position: results[0].geometry.location
                        });
                    } else {
                        alert('Geocode was not successful for the following reason: ' + status);
                    }
                }
            }(i)
        );
    }
}

google.maps.event.addDomListener(window, 'load', initialize);

Tell me how to change the code so that instead of addresses in the top line, you can write coordinates (latitude and longitude)?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Alexander, 2017-07-16
@NeiroNx

Instead of codeAddress();

var position = {lat: 59.325, lng: 18.070};
map.setCenter(position);
var marker = new google.maps.Marker({
                            map: map,
                            position: position
                        });

https://developers.google.com/maps/documentation/j...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question