我有以下代码,当我将地图上的标记拖到其位置时,它将更新带有位置纬度/经度的文本框:
var listener = function (evt) {
/* We check if this drag listener is called while the marker is being
* dragged using the default behavior component
*/
var mapDragType = evt.dataTransfer.getData("application/map-drag-type");
if (mapDragType === "marker") {
// Get the marker itself.
var marker = evt.dataTransfer.getData("application/map-drag-object");
// Get the offset of the mouse relative to the top-left corner of the marker.
var offset = evt.dataTransfer.getData("application/map-drag-object-offset");
/* Calculate the current coordinate of the marker, so substract the offset from the
* current displayX/Y position to get the top-left position of the marker and then
* add the anchor to get the pixel position of the anchor of the marker and then
* query for the coordinate of that pixel position
*/
var coordinate = map.pixelToGeo(evt.displayX - offset.x + marker.anchor.x, evt.displayY - offset.y + marker.anchor.y);
// If the marker is dragged above a zone where it may not be dropped
if (evt.dataTransfer.dropEffect === "none") {
// If this is the end of the drag
if (evt.type === "dragend") {
// then the marker will jump back to where it was;
updateInputValue(marker, marker.coordinate.toString());
}
else {
// otherwise it is currently (while being dragged) above an invalid drop zone
updateInputValue(marker, "Invalid drop zone!");
}
}
else {
// If the marker is somewhere above the map, update info text with the new coordinate.
updateInputValue(marker, coordinate.toString());
}
}
};
/* Create a helper method that updates the text fields associated with the
* marker passed as argument
*/
var updateInputValue = function (draggedMarker, text) {
if (draggedMarker === marker)
$("input[name*='txtGeoLocation']").val(text);
//markerPosUiElt.innerHTML = text;
};
我遇到的问题是,当我需要十进制格式时,纬度/经度以长格式输出。
我尝试更改以下几行:
updateInputValue(marker, marker.coordinate.toString());
到以下:
updateInputValue(marker, marker.coordinate.latitude.ToString() + ', ' + marker.coordinate.longitude.ToString());
但是然后我的文本框停止填充(我想一个错误正在抛出,它没有冒泡)。我什至尝试使用以下方法检索纬度:
updateInputValue(marker, marker.coordinate.latitude.ToString());
但我仍然没有收到任何输出。
我怎样才能做到这一点?我绝对不想要长格式的纬度/经度,只希望将十进制版本写到我的文本框中。