[英]Find the user's location and display it in pop up in a single post back
需要顯示用戶的地理位置(ZipCode)並在頁面加載期間顯示它。 目前,我正在通過2個回發實現這一目標,有沒有辦法在單個回發中實現。
謝謝
我嘗試過的:
function ShowMessages() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(success);
} else {
alert("Geo Location is not supported on your current browser!");
}
function success(position) {
debugger;
var lat = position.coords.latitude;
var lng = position.coords.longitude;
var latlng = new google.maps.LatLng(lat, lng);
var geocoder = geocoder = new google.maps.Geocoder();
geocoder.geocode({'latLng': latlng},
function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
var searchAddressComponents = results[0].address_components,
searchPostalCode = "";
$.each(searchAddressComponents, function () {
if (this.types[0] == "postal_code") {
searchPostalCode = this.short_name;
}
});
document.getElementById('hidden1').value = searchPostalCode
__doPostBack('', '');
}
}
});
}
}
如果可以找到searchPostalCode的值,則將其顯示為span,該范圍將在彈出的div上移動。
document.getElementById('hidden1').value = searchPostalCode;
document.getElementById('YourSpan').innerText = searchPostalCode;
$("#YourDiv").append($("#YourSpan"));
$("#YourDiv").modal();//Apply your modal code here
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.