Asp.net получает значение метки из codebehind. для координат карт Google
Я не могу получить значение метки в коде позади. Я хотел бы сохранить координаты с карты Google. Вы можете помочь мне увидеть, чего мне не хватает?
HTML
<span>Location:</span>
<input type="text" id="txtPlaces" style="width: 250px" placeholder="Enter a location" />
<div id="dvMap" style="width: 100%; height:300px;">
<asp:Label ID="Label1" runat="server"></asp:Label>
<asp:Label ID="Label2" runat="server"></asp:Label>
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
Javascript
<script type="text/javascript">
google.maps.event.addDomListener(window, 'load', function () {
var places = new google.maps.places.Autocomplete(document.getElementById('txtPlaces'));
google.maps.event.addListener(places, 'place_changed', function () {
var place = places.getPlace();
var address = place.formatted_address;
var latitude = place.geometry.location.lat();
var longitude = place.geometry.location.lng();
var mesg = "Address: " + address;
mesg += "\nLatitude: " + latitude;
mesg += "\nLongitude: " + longitude;
document.getElementById('Label1').textContent = latitude;
document.getElementById('Label2').textContent = longitude;
var lat = document.getElementById('Label1').textContent;
var lon = document.getElementById('Label2').textContent;
var mapOptions = {
center: new google.maps.LatLng(lat, lon),
zoom: 16,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var latlngbounds = new google.maps.LatLngBounds();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
google.maps.event.addListener(map, 'click', function (e) {
// alert("Latitude: " + e.latLng.lat() + "\r\nLongitude: " + e.latLng.lng());
});
alert(mesg);
});
});
</script>
CodeBehind
пример строки = Label1.Text; // или innerhtml или innertext..
1 ответ
Решение
Изменения в метках, а также в элементах без ввода, например divs
, spans
и т.д., не будут опубликованы из-за природы HTTP Post.
Что бы я сделал на вашем месте, это добавить скрытое и установить значение, которое вы хотите разместить там. Просто как то так:
<input runat="server" ID="Label1Value" class="form-control" type="hidden" />