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 ?