我正在構建一個JavaScript函數,加載谷歌地圖內shadowbox,這是很容易使用此代碼(我使用插件calld GeoPlugin獲取經度和緯度,因爲我現在不怎麼得到我lat和自動長):谷歌地圖和shadowbox
function initGeoLocationOnDemand() {
$('a.btnInitGeoLoc').click(function() {
if (GBrowserIsCompatible()) {
Shadowbox.open({
player: "html",
content: "",
height: 300,
width: 500,
options: {
onFinish: function (item) {
var body = document.getElementById(Shadowbox.playerId);
var map = new GMap2(body);
//using geoPlugin to get lat and long
var point = new GLatLng(geoplugin_latitude(), geoplugin_longitude());
map.setCenter(point, 15);
var marker = new GMarker(point);
var addrFields = ['street_address'];
map.addOverlay(marker);
marker.openInfoWindow(document.createTextNode("hello");
// add some simple controls
map.addControl(new GSmallMapControl());
map.addControl(new GMapTypeControl());
}
}
});
} else {
alert("Your browser is not compatible with Google Maps!");
}
});
Shadowbox.init();
}
現在我想用塗到GoogleMaps Reverse Geocoding獲得谷歌地圖標記信息的信息等窗口內:城市名稱,國家名稱,街道名稱,郵政編碼,等等
我做了這段代碼,關注GoogleMaps api,但它不工作了......總是使用GeoPlugin:
function initGeoLocationOnDemand() {
$('a.btnInitGeoLoc').click(function() {
if (GBrowserIsCompatible()) {
Shadowbox.open({
player: "html",
content: "",
height: 300,
width: 800,
options: {
onFinish: function (item) {
var body = document.getElementById(Shadowbox.playerId);
var geocoder;
var map = new google.maps.Map(body);
var infowindow = new google.maps.InfoWindow();
var marker;
function initialize() {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(geoplugin_latitude(),geoplugin_longitude());
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(body, myOptions);
}
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(11);
marker = new google.maps.Marker({
position: latlng,
map: map
});
infowindow.setContent(results[1].formatted_address);
infowindow.open(map, marker);
}
} else {
alert("Geocoder failed due to: " + status);
}
});
}
}
}
});
} else {
alert("Your browser is not compatible with Google Maps!");
}
});
Shadowbox.init();
}
有沒有一種方法來獲取緯度和經度,而不使用插件?
有一種方法可以獲取有關國家名稱,城市名稱,街道名稱,郵政編碼等信息?
在此先感謝您的幫助!
很好解釋...我想得到的東西,如果你允許在我的網站geoLocation我想要得到街道名稱,國家名稱,城市名稱,郵政編碼等... –
沒有固定的地方...使用GeoLocation的動態地點。 –
只有一種可能性來獲取這種信息 - 從地理位置數據庫將您的網站訪問者的IP地址與其地理位置聯繫起來。什麼都不存儲在JS可以訪問的訪問者的客戶端機器上。所以這可能是你的問題的答案,如果你可以在沒有插件的情況下獲取數據。 –