gpt4 book ai didi

javascript - 如何从 getter 中设置值?

转载 作者:行者123 更新时间:2023-12-01 05:42:21 25 4
gpt4 key购买 nike

如何从response.loc设置地理编码:$("#details").html("Location: "+ response.loc);

作为以下值:var latlng = new google.maps.LatLng(59.6162,16.5528);

var geocoder;
var map;
var infowindow = new google.maps.InfoWindow();
var marker;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(59.6162,16.5528);
var mapOptions = {
zoom: 13,
center: latlng,
mapTypeId: 'hybrid'
}
map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
}

function codeLatLng() {
var input = document.getElementById('latlng').value;
var latlngStr = input.split(',', 2);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
map.setZoom(15);
marker = new google.maps.Marker({
position: latlng,
map: map

});
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}

google.maps.event.addDomListener(window, 'load', initialize);

// get geocode from IP //

$.get("http://ipinfo.io", function (response) {
$("#ip").html("Your IP: " + response.ip);
$("#address").html("Location: " + response.city + ", " + response.region);
$("#details").html("Location: " + response.loc);
}, "jsonp");

最佳答案

您可以将response.loc作为参数传递给函数codeLatLng。

function codeLatLng(loc) {
var latlngStr = input.split(',', loc);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
if (results[1]) {
map.setZoom(15);
marker = new google.maps.Marker({
position: latlng,
map: map

});
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
} else {
alert('No results found');
}
} else {
alert('Geocoder failed due to: ' + status);
}
});
}

google.maps.event.addDomListener(window, 'load', initialize);

// get geocode from IP //

$.get("http://ipinfo.io", function (response) {
$("#ip").html("Your IP: " + response.ip);
$("#address").html("Location: " + response.city + ", " + response.region);
$("#details").html("Location: " + response.loc);
codeLatLng(response.loc);
}, "jsonp");

关于javascript - 如何从 getter 中设置值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29962091/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com