我正在构建一个在 shadowbox 中加载谷歌地图的 javascript 函数,使用此代码非常容易(我使用名为 GeoPlugin 的插件来获取纬度和经度,因为我现在不知道如何自动获取我的纬度和经度):
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 标记信息中的信息窗口,例如:城市名称、国家名称、街道名称、邮政编码等...
我按照 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();
}
有一种方法可以在不使用插件的情况下获得纬度和经度?
有没有办法获取有关国家名称、城市名称、街道名称、邮政编码等信息?
在此先感谢您的帮助!