在谷歌地图中使用密码作为中心 [英] use pincode as center in google maps
本文介绍了在谷歌地图中使用密码作为中心的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的网站上使用谷歌地图,默认情况下,在初始化地图时需要经度和经度来显示中心区域。我有纬度,经度和密码变量,所以我希望当我的纬度和经度有值时,它会在初始化时显示在地图上但当它们为空时将我的密码显示为地图上的中心。
I am using google map in my website, bydefault it takes latitude and longitude to display center area during intializing the map. I have latitude, longitude and pincode variable, so i want when my latitude and longitude have values then it show on map during initializing but when they are empty display my pincode as center on the map.
var lat = '<%=lat%>';
var lon = '<%=lon%>';
var pincode = '<%=mappincode%>';
function first()
{
if (!lat || !lon) {
geocoder.geocode({ 'address': pincode }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = results[0].geometry.location.lat();
lon = results[0].geometry.location.lng();
InitializeMap();
}
});
} else {
InitializeMap();
}
}
function InitializeMap() {
var latlng = new google.maps.LatLng(lat, lon);
var myOptions =
{
zoom: 13,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var map = new google.maps.Map(document.getElementById("Gmap"), myOptions);
window.onload = first;
<div id ="Gmap" style="height: 300px; width: 600px; removed 25px; removed 25px;" ></div>
推荐答案
这篇关于在谷歌地图中使用密码作为中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文