I guess you want to obtain the coordinates of the pixel of the
viewport under the pointer.
The problem is that method fromLatLngToPoint returns the point in
"world coordinates".
To obtain the pixel you need to translate the point with respect to
the origin of the viewport (the upper left corner), and then scale
with respect to the zoom level of the map. Try this:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://
www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/
html;charset=ISO-8859-1">
    <title>Insert title here</title>
    <style type="text/css">
     #map {
       width: 800px;
       height: 600px;
     }

     #latlng-control {
       background: #ffc;
       position: absolute;
       top:100px;
       left:100px;
       width:150px;
       height:40px;
     }
   </style>

    <script type="text/javascript" src="http://maps.google.com/maps/
api/js?sensor=false"></script>

    <script type="text/javascript">
       var map;
       function init() {
       var centerLatLng = new
google.maps.LatLng(37.748582,-122.418411);
       map = new google.maps.Map(document.getElementById('map'), {
         'zoom': 10,
         'center': centerLatLng,
         'mapTypeId': google.maps.MapTypeId.ROADMAP
       });
       registerListener();
       }

       function registerListener(){
       google.maps.event.addListener(map, 'mousemove',function(mEvent)
{
               var point = convertPoint(mEvent.latLng);
               var elem = document.getElementById('latlng-control');
               elem.innerHTML = point.x+"<br>"+point.y;
         });
       }

       function convertPoint(latLng) {
         var
topRight=map.getProjection().fromLatLngToPoint(map.getBounds().getNorthEast());
         var
bottomLeft=map.getProjection().fromLatLngToPoint(map.getBounds().getSouthWest());
         var scale=Math.pow(2,map.getZoom());
         var worldPoint=map.getProjection().fromLatLngToPoint(latLng);
         return new google.maps.Point((worldPoint.x-
bottomLeft.x)*scale,(worldPoint.y-topRight.y)*scale);
       }


   google.maps.event.addDomListener(window, 'load', init);
    </script>

</head>
<body>
    <div id="map">
    </div>
    <div id="latlng-control">
    </div>
</body>
</html>


Ciao.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps JavaScript API v3" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-js-api-v3?hl=en.

Reply via email to