javascript - Google maps function fromLatLngToContainerPixel(LatLng) not working -


im trying pixel coordinates of market using fromlatlngtocontainerpixel(latlng) function. not sure how use after searching examples in think got it. problem function returns "undifined".

google maps api ref: https://developers.google.com/maps/documentation/javascript/reference?csw=1#mapcanvasprojection

please help.

code:

var map, overlay;  function initialize() { var mylatlng = new google.maps.latlng(-25.363882, 131.044922); map = new google.maps.map(document.getelementbyid('gmap'), {     zoom : 13,     center : mylatlng,     disabledefaultui: true,     draggable: false,     scrollwheel: false,     disabledoubleclickzoom: true });  var overlay = new google.maps.overlayview(); overlay.draw = function () {}; overlay.setmap(map);  var marker = new google.maps.marker({     position: mylatlng,      optimized: false,      map:map });   var projection = overlay.getprojection();          var pixel =     projection.fromlatlngtocontainerpixel(marker.getposition());         console.log(pixel); } google.maps.event.adddomlistener(window, 'load', initialize); 

from documentation:

getprojection(): returns mapcanvasprojection object associated overlayview. projection not initialized until onadd called api.

onadd(): implement method initialize overlay dom elements. method called once after setmap() called valid map. @ point, panes , projection have been initialized.

so solution is: implement onadd()-method , access projection inside onadd():

function initialize() {   var mylatlng = new google.maps.latlng(-25.363882, 131.044922);   map = new google.maps.map(document.getelementbyid('gmap'), {     zoom: 13,     center: mylatlng,     disabledefaultui: true,     draggable: false,     scrollwheel: false,     disabledoubleclickzoom: true   });    var marker = new google.maps.marker({     position: mylatlng,     optimized: false,     map: map   });    var overlay = new google.maps.overlayview();   overlay.draw = function() {};   overlay.onadd = function() {     var projection = this.getprojection();     var pixel = projection.fromlatlngtocontainerpixel(marker.getposition());     console.log(pixel);   };   overlay.setmap(map); } 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -