Click here to Skip to main content
15,889,931 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 ?
Posted

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900