如何在Google地图中设置标签城市的当前位置 [英] How to Set Current Location from Label city in Google Maps

查看:125
本文介绍了如何在Google地图中设置标签城市的当前位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello To All



我有一个脚本可以正常使用用户的GEO位置,当有人点击联系我们页面时当前正常工作,但在这里我想做一些修改,在用户地理定位将被跟踪,并从标签中提到的具有从数据库获取的数据的城市将被考虑作为目的地;截至目前,当我将lblcity设置为当前位置时,地图会加载,但会显示一个空白的灰色地图:



需要将用户当前位置设置为此Google地图脚本,我有目的地设置只想从用户当前位置呼叫原点。



< script type =text / javascript>



(功能(){



var directionsService = new google.maps.DirectionsService(),

directionsDisplay = new google.maps.DirectionsRenderer(),



createMap = function(start){

var travel = {

来源:( start.coords)?new google.maps.LatLng(start.lat,start.lng):start.address,

// destination:Country Club,Sainik农场,

目的地:<%= lbldocprofaddress%>,

// destinati on:Saket,

travelMode:google.maps.DirectionsTravelMode.DRIVING

//将DRIVING交给WALKING可以证明非常有趣:-)

},

mapOptions = {

zoom:1,

//默认视图:斯德哥尔摩市中心

// center:new google.maps.LatLng(59.3325215,18.0643818),

mapTypeId:google.maps.MapTypeId.ROADMAP

};





map = new google.maps.Map(document.getElementById(map),mapOptions);

directionsDisplay.setMap (地图);

//directionsDisplay.setPanel(document.getElementById(\"map-directions));

directionsDisplay.setPanel(document.getElementById('panel') );

directionsService.route(旅行,功能(re。) sult,status){

if(status === google.maps.DirectionsStatus.OK){

directionsDisplay.setDirections(result);

}

});

};





//检查地理定位支持

if(navigator.geolocation){

// navigator.geolocation.clearWatch(watchID);

var watchID = navigator。 geolocation.getCurrentPosition(function(position){

//navigator.geolocation.getCurrentPosition(function(position){

//成功!

createMap({

coords:true,

lat:position.coords.latitude,

lng:position.coords.longitude

});

},

function(){

// Gelocation回退:默认为瑞典斯德哥尔摩

createMap( {

coords:false,

地址:新德里

});

}

);

}

else {

//没有地理位置后备:默认为里斯本,葡萄牙

createMap({

coords:false,

地址:新德里

});

}

})();

< / script>



我无法理解我在哪里出错了,lbldocprofaddress数据正从SQL服务器获取,上面的脚本正在Asp.net中使用c#。



请指导我哪里出错?

解决方案

没有人对他说lp ???



常见这里有很多经验丰富的专业人士可以帮助我解决这个问题,因为我对这个领域全新

Hello To All

I have a script which is working fine with the GEO location of the user which is currently working fine when some one clicks on contact us page, but out here I want to make some modifications where in the user geolocation would be tracked and from the city mentioned in the label which has data fetched from database would be taken into consideration as destination; as of now when I set lblcity to current location the map loads but a blank grey map is being shown :

One needs to set user current location to this google map script, I have the destination set just want to call origin from user current location.

<script type="text/javascript">

(function () {

var directionsService = new google.maps.DirectionsService(),
directionsDisplay = new google.maps.DirectionsRenderer(),

createMap = function (start) {
var travel = {
origin: (start.coords) ? new google.maps.LatLng(start.lat, start.lng) : start.address,
//destination: "Country Club, Sainik Farms",
destination: "<%=lbldocprofaddress%>",
//destination: "Saket",
travelMode: google.maps.DirectionsTravelMode.DRIVING
// Exchanging DRIVING to WALKING above can prove quite amusing :-)
},
mapOptions = {
zoom: 1,
// Default view: downtown Stockholm
//center : new google.maps.LatLng(59.3325215, 18.0643818),
mapTypeId: google.maps.MapTypeId.ROADMAP
};


map = new google.maps.Map(document.getElementById("map"), mapOptions);
directionsDisplay.setMap(map);
//directionsDisplay.setPanel(document.getElementById("map-directions"));
directionsDisplay.setPanel(document.getElementById('panel'));
directionsService.route(travel, function (result, status) {
if (status === google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(result);
}
});
};


// Check for geolocation support
if (navigator.geolocation) {
// navigator.geolocation.clearWatch(watchID);
var watchID = navigator.geolocation.getCurrentPosition(function (position) {
//navigator.geolocation.getCurrentPosition(function (position) {
// Success!
createMap({
coords: true,
lat: position.coords.latitude,
lng: position.coords.longitude
});
},
function () {
// Gelocation fallback: Defaults to Stockholm, Sweden
createMap({
coords: false,
address: "New Delhi"
});
}
);
}
else {
// No geolocation fallback: Defaults to Lisbon, Portugal
createMap({
coords: false,
address: "New Delhi"
});
}
})();
</script>

I cannot understad where am I going wrong, lbldocprofaddress data is being fetched from SQL server and the above script is being used in Asp.net c#.

Please guide where did I went wrong ?

解决方案

No one to help ???

Common there are a lot of highly experienced professional out here can any one help me with the solution to this problem as I am totally new to this field


这篇关于如何在Google地图中设置标签城市的当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆