无法从谷歌地图获取纬度和经度变量

时间:2015-03-30 16:16:04

标签: javascript google-maps google-maps-api-3 location dhtmlx

我想在点击谷歌地图上的标记时,在输入字段中显示纬度和经度变量。但是现在,我刚刚收到NaN,我不知道为什么。

infowindow.open(gMap, marker);

var a = new google.maps.LatLng();

var lat = a.lat();
var lng = a.lng();

alert(3);

FormData2 =
[
    {type: "settings", position: "label-left", labelWidth: 100, inputWidth: 300},



    {type: "button", name: "mapButton", value:"Open Map", width: "100", inputLeft:550, inputTop: 8, position: "absolute"},
    {type: "input", name: "latitude", label: "Latitude", value: lat, width: "150", labelLeft: 500, labelTop: 40, inputLeft: 600, inputTop: 40, position: "absolute"},
    {type: "input", name: "longitude", label: "Longitude", value: lng, width: "150", labelLeft: 500, labelTop: 70, inputLeft: 600, inputTop: 70, position: "absolute"},
    {type: "block", inputWidth: "auto", offsetTop: 4, list: 
    [
        {type: "combo", name: "stateCombo", label: "State", value: "0"},
        {type: "combo", name: "cTypeCombo", label: "C", value: "2", options: 
        [
            {value: "1", text: "County"},
            {value: "2", text: "C", selected: true}
        ]},

        {type: "combo", name: "climateCombo", label: "Station", value: ""},
        {type:"newColumn"}, 
    ]},

];



form = panel.attachForm(FormData2);
});

1 个答案:

答案 0 :(得分:0)

您可能想要标记的位置:

google.maps.event.addListener(marker, 'click', function() {

            infowindow.open(gMap, marker);

            var a = this.getPosition(); // or marker.getPosition()

            var lat = a.lat();
            var lng = a.lng();

            alert(3);