A
A
Albert Tobacco2014-10-14 10:28:55
Google Maps
Albert Tobacco, 2014-10-14 10:28:55

Google API, when clicking on the map go to google map to the same location with a marker?

The problem is that the task is with a custom marker, that is, I form the map with code

function drawMap(address, iconUrl){
  
  var firstLatlng = new google.maps.LatLng(42.3551142, -71.0594341);
  var firstOptions = {
      zoom: 19,
      center: firstLatlng,
      mapTypeId: google.maps.MapTypeId.ROADMAP,
      disableDefaultUI: true,
      draggable: false,
    };

  window.map = new google.maps.Map(document.getElementById("contact-google_map"), firstOptions);
    
  geocoder = new google.maps.Geocoder();
    geocoder.geocode({'address': address}, function (results, status) {
        if (status == google.maps.GeocoderStatus.OK) {
      
      var markerLoc =  results[0].geometry.location;
      
            map.setCenter(results[0].geometry.location);
            var marker = new google.maps.Marker({
                map: map,
                position: results[0].geometry.location,                            
                draggable: false,
                icon: iconUrl
            });    
            
            var loc = 'https://www.google.com.ua/maps/@' + markerLoc.k +',' + markerLoc.B +',19z';
            
            google.maps.event.addListener(marker, 'click', function () {
                window.location.href = loc;
            }); 
            google.maps.event.addListener(map, 'click', function () {
                window.location.href = loc;
            }); 
        }
    });
}

I implemented the transition using .addListener, it works, but the transition does not have a marker, but it is needed.
Has anyone experienced this? How to implement?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question