将浏览器坐标-x,y-转换为google maps latitude&没有点击监听的经度?

时间:2014-03-25 16:51:16

标签: javascript google-maps

我想问一下是否有办法将浏览器中某个地方的x,y坐标转换为谷歌地图坐标而不在javascript中添加点击监听器?

我已经拥有了浏览器的像素坐标,但我需要将其转换为地理形式供以后使用;用户点击不会生成像素坐标。

更新:我发现在我之前提出了一个非常有用的问题:Create google maps markers from pixel xy coordinates

除了从叠加变量获取投影外,其他所有内容都有效。

我的剧本:

function initialize()
{

   //Not related to the problem ; 

    latlng_local = markerData.split('@');
    lat = latlng_local[0];

    lng = latlng_local[1];
    latlng = new google.maps.LatLng(lat, lng);


    var mapOptions = 

    {
    center: new google.maps.LatLng(lat, lng),
    zoom: 8
    };

    map = new google.maps.Map(document.getElementById("map"),
                              mapOptions);    


    loadUserAndFriends();
    var overlay = new google.maps.OverlayView();
    overlay.draw = function() {};
    overlay.setMap(map);


//My question starts from here
    google.maps.event.addListenerOnce(map,"idle", handleRandCoord() );


}


function handleRandCoord()
{    alert('xx');
    xhRequest.open("GET", "http://sample", false);
    xhRequest.send(null);



    var proximityList = new Array();
    proximityList = markerData.split('@');


//Problem is in here ; the script stops once I call overlay.getProjection()
    var pixelLatLng = overlay.getProjection().fromDivPixelToLatLng( new google.maps.Point(200,200) );
    alert("ss");





    var populationOptions = {
    strokeColor: '#FF0000',
    strokeOpacity: 0.8,
    strokeWeight: 2,
    fillColor: '#FF0000',
    fillOpacity: 0.35,
    map: map,
    };
    // Add the circle for this city to the map.
   var cityCircle = new google.maps.Circle(populationOptions);
    cityCircle.setCenter(pixelLatLng);
    cityCircle.setRadius(proximityList[1] );
    cityCircle.setMap(map);



}

0 个答案:

没有答案