I"m having of problem using map in mvc application, map is not shown in view while there is no error in...
0
<script type="text/javascript">
// Google mapper initialize function
function initialize() {
//To find the current location and add the marker of current location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
}
else { $("#message").html("Geolocation is not supported by this browser."); }
function showPosition(position) {
var currentLatLng = position.coords;
var latlon = "Latitude" + currentLatLng.latitude + "," + "Longitude" + currentLatLng.longitude;
//Google map options like langitude, latitude and zoom level
var mapOptions = {
center: new google.maps.LatLng(currentLatLng.latitude, currentLatLng.longitude),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var geocoder = new google.maps.Geocoder;
//Get the element of div to show google maps
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('right-panel'));
var control = document.getElementById('floating-panel');
//control.style.display = 'block';
map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);
// adding the user current location to teh marker
addMarker(currentLatLng.latitude, currentLatLng.longitude, "You are here. Please wait. System is locating near by locations");
// Ajax call to get the nearest locations from DB.
jQuery.ajax({
cache: false,
type: "POST",
url: "@Url.Action("GetNearByLocations")",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Currentlat: currentLatLng.latitude, Currentlng: currentLatLng.longitude }),
success: function (data) {
//Adding the marker of nearest locations
if (data != undefined) {
$.each(data, function (i, item) {
// addMarker(item["lat"], item["lng"], item["Name"] + " & Distance: " + (Math.round(0.0 + item["Distance"] / 1000)) + " KM");
addMarker(item["lat"], item["lng"], "Click to get directions");
})
}
},
failure: function (errMsg) {
alert(errMsg);
}
});
// Add marker function to add the markers and information window settings
function addMarker(x, y, locationName, distance) {
var infowindow = new google.maps.InfoWindow({
content: locationName
});
var location = new google.maps.LatLng(x, y);
var marker = new google.maps.Marker({
position: location,
map: map,
title: locationName,
});
infowindow.open(map, marker);
// Call the funtion to draw the route map on the clicking on the map marker
marker.addListener('click', function () {
infowindow.open(map, marker);
calculateAndDisplayRoute(directionsService, directionsDisplay, x, y);
});
}
//function to draw the route from the current location to the clicked location on the map
function calculateAndDisplayRoute(directionsService, directionsDisplay, x, y) {
// Origin is user current location
var latlngSource = { lat: parseFloat(currentLatLng.latitude), lng: parseFloat(currentLatLng.longitude) };
//destination is clicked marker on the map
var latlangDestination = { lat: parseFloat(x), lng: parseFloat(y) };
directionsService.route({
origin: latlngSource, //Source
destination: latlangDestination, //destination
travelMode: 'DRIVING'
}, function (response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
}
//show error formats incase the location is not found.
function showError(error) {
if (error.code == 1) {
$("#message").html("User denied the request for Geolocation.");
}
else if (error.code == 2) {
$("#message").html("Location information is unavailable.");
}
else if (error.code == 3) {
$("#message").html("The request to get user location timed out.");
}
else {
$("#message").html("An unknown error occurred.");
}
}
}
// Google maper - starting point
google.maps.event.addDomListener(window, 'load', initialize);
</script>
c# jquery
add a comment |
0
<script type="text/javascript">
// Google mapper initialize function
function initialize() {
//To find the current location and add the marker of current location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
}
else { $("#message").html("Geolocation is not supported by this browser."); }
function showPosition(position) {
var currentLatLng = position.coords;
var latlon = "Latitude" + currentLatLng.latitude + "," + "Longitude" + currentLatLng.longitude;
//Google map options like langitude, latitude and zoom level
var mapOptions = {
center: new google.maps.LatLng(currentLatLng.latitude, currentLatLng.longitude),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var geocoder = new google.maps.Geocoder;
//Get the element of div to show google maps
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('right-panel'));
var control = document.getElementById('floating-panel');
//control.style.display = 'block';
map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);
// adding the user current location to teh marker
addMarker(currentLatLng.latitude, currentLatLng.longitude, "You are here. Please wait. System is locating near by locations");
// Ajax call to get the nearest locations from DB.
jQuery.ajax({
cache: false,
type: "POST",
url: "@Url.Action("GetNearByLocations")",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Currentlat: currentLatLng.latitude, Currentlng: currentLatLng.longitude }),
success: function (data) {
//Adding the marker of nearest locations
if (data != undefined) {
$.each(data, function (i, item) {
// addMarker(item["lat"], item["lng"], item["Name"] + " & Distance: " + (Math.round(0.0 + item["Distance"] / 1000)) + " KM");
addMarker(item["lat"], item["lng"], "Click to get directions");
})
}
},
failure: function (errMsg) {
alert(errMsg);
}
});
// Add marker function to add the markers and information window settings
function addMarker(x, y, locationName, distance) {
var infowindow = new google.maps.InfoWindow({
content: locationName
});
var location = new google.maps.LatLng(x, y);
var marker = new google.maps.Marker({
position: location,
map: map,
title: locationName,
});
infowindow.open(map, marker);
// Call the funtion to draw the route map on the clicking on the map marker
marker.addListener('click', function () {
infowindow.open(map, marker);
calculateAndDisplayRoute(directionsService, directionsDisplay, x, y);
});
}
//function to draw the route from the current location to the clicked location on the map
function calculateAndDisplayRoute(directionsService, directionsDisplay, x, y) {
// Origin is user current location
var latlngSource = { lat: parseFloat(currentLatLng.latitude), lng: parseFloat(currentLatLng.longitude) };
//destination is clicked marker on the map
var latlangDestination = { lat: parseFloat(x), lng: parseFloat(y) };
directionsService.route({
origin: latlngSource, //Source
destination: latlangDestination, //destination
travelMode: 'DRIVING'
}, function (response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
}
//show error formats incase the location is not found.
function showError(error) {
if (error.code == 1) {
$("#message").html("User denied the request for Geolocation.");
}
else if (error.code == 2) {
$("#message").html("Location information is unavailable.");
}
else if (error.code == 3) {
$("#message").html("The request to get user location timed out.");
}
else {
$("#message").html("An unknown error occurred.");
}
}
}
// Google maper - starting point
google.maps.event.addDomListener(window, 'load', initialize);
</script>
c# jquery
Hail The Wall of Unformatted Code! *_*
– iamdanchiv
Jan 1 at 7:25
do you have a div with map id in your .cshtml code.
– Anirudha Gupta
Jan 1 at 9:15
add a comment |
0
0
0
<script type="text/javascript">
// Google mapper initialize function
function initialize() {
//To find the current location and add the marker of current location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
}
else { $("#message").html("Geolocation is not supported by this browser."); }
function showPosition(position) {
var currentLatLng = position.coords;
var latlon = "Latitude" + currentLatLng.latitude + "," + "Longitude" + currentLatLng.longitude;
//Google map options like langitude, latitude and zoom level
var mapOptions = {
center: new google.maps.LatLng(currentLatLng.latitude, currentLatLng.longitude),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var geocoder = new google.maps.Geocoder;
//Get the element of div to show google maps
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('right-panel'));
var control = document.getElementById('floating-panel');
//control.style.display = 'block';
map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);
// adding the user current location to teh marker
addMarker(currentLatLng.latitude, currentLatLng.longitude, "You are here. Please wait. System is locating near by locations");
// Ajax call to get the nearest locations from DB.
jQuery.ajax({
cache: false,
type: "POST",
url: "@Url.Action("GetNearByLocations")",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Currentlat: currentLatLng.latitude, Currentlng: currentLatLng.longitude }),
success: function (data) {
//Adding the marker of nearest locations
if (data != undefined) {
$.each(data, function (i, item) {
// addMarker(item["lat"], item["lng"], item["Name"] + " & Distance: " + (Math.round(0.0 + item["Distance"] / 1000)) + " KM");
addMarker(item["lat"], item["lng"], "Click to get directions");
})
}
},
failure: function (errMsg) {
alert(errMsg);
}
});
// Add marker function to add the markers and information window settings
function addMarker(x, y, locationName, distance) {
var infowindow = new google.maps.InfoWindow({
content: locationName
});
var location = new google.maps.LatLng(x, y);
var marker = new google.maps.Marker({
position: location,
map: map,
title: locationName,
});
infowindow.open(map, marker);
// Call the funtion to draw the route map on the clicking on the map marker
marker.addListener('click', function () {
infowindow.open(map, marker);
calculateAndDisplayRoute(directionsService, directionsDisplay, x, y);
});
}
//function to draw the route from the current location to the clicked location on the map
function calculateAndDisplayRoute(directionsService, directionsDisplay, x, y) {
// Origin is user current location
var latlngSource = { lat: parseFloat(currentLatLng.latitude), lng: parseFloat(currentLatLng.longitude) };
//destination is clicked marker on the map
var latlangDestination = { lat: parseFloat(x), lng: parseFloat(y) };
directionsService.route({
origin: latlngSource, //Source
destination: latlangDestination, //destination
travelMode: 'DRIVING'
}, function (response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
}
//show error formats incase the location is not found.
function showError(error) {
if (error.code == 1) {
$("#message").html("User denied the request for Geolocation.");
}
else if (error.code == 2) {
$("#message").html("Location information is unavailable.");
}
else if (error.code == 3) {
$("#message").html("The request to get user location timed out.");
}
else {
$("#message").html("An unknown error occurred.");
}
}
}
// Google maper - starting point
google.maps.event.addDomListener(window, 'load', initialize);
</script>
c# jquery
<script type="text/javascript">
// Google mapper initialize function
function initialize() {
//To find the current location and add the marker of current location
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition, showError);
}
else { $("#message").html("Geolocation is not supported by this browser."); }
function showPosition(position) {
var currentLatLng = position.coords;
var latlon = "Latitude" + currentLatLng.latitude + "," + "Longitude" + currentLatLng.longitude;
//Google map options like langitude, latitude and zoom level
var mapOptions = {
center: new google.maps.LatLng(currentLatLng.latitude, currentLatLng.longitude),
zoom: 6,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var directionsService = new google.maps.DirectionsService;
var directionsDisplay = new google.maps.DirectionsRenderer;
var geocoder = new google.maps.Geocoder;
//Get the element of div to show google maps
var map = new google.maps.Map(document.getElementById("map"),
mapOptions);
directionsDisplay.setMap(map);
directionsDisplay.setPanel(document.getElementById('right-panel'));
var control = document.getElementById('floating-panel');
//control.style.display = 'block';
map.controls[google.maps.ControlPosition.TOP_CENTER].push(control);
// adding the user current location to teh marker
addMarker(currentLatLng.latitude, currentLatLng.longitude, "You are here. Please wait. System is locating near by locations");
// Ajax call to get the nearest locations from DB.
jQuery.ajax({
cache: false,
type: "POST",
url: "@Url.Action("GetNearByLocations")",
dataType: "json",
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ Currentlat: currentLatLng.latitude, Currentlng: currentLatLng.longitude }),
success: function (data) {
//Adding the marker of nearest locations
if (data != undefined) {
$.each(data, function (i, item) {
// addMarker(item["lat"], item["lng"], item["Name"] + " & Distance: " + (Math.round(0.0 + item["Distance"] / 1000)) + " KM");
addMarker(item["lat"], item["lng"], "Click to get directions");
})
}
},
failure: function (errMsg) {
alert(errMsg);
}
});
// Add marker function to add the markers and information window settings
function addMarker(x, y, locationName, distance) {
var infowindow = new google.maps.InfoWindow({
content: locationName
});
var location = new google.maps.LatLng(x, y);
var marker = new google.maps.Marker({
position: location,
map: map,
title: locationName,
});
infowindow.open(map, marker);
// Call the funtion to draw the route map on the clicking on the map marker
marker.addListener('click', function () {
infowindow.open(map, marker);
calculateAndDisplayRoute(directionsService, directionsDisplay, x, y);
});
}
//function to draw the route from the current location to the clicked location on the map
function calculateAndDisplayRoute(directionsService, directionsDisplay, x, y) {
// Origin is user current location
var latlngSource = { lat: parseFloat(currentLatLng.latitude), lng: parseFloat(currentLatLng.longitude) };
//destination is clicked marker on the map
var latlangDestination = { lat: parseFloat(x), lng: parseFloat(y) };
directionsService.route({
origin: latlngSource, //Source
destination: latlangDestination, //destination
travelMode: 'DRIVING'
}, function (response, status) {
if (status === 'OK') {
directionsDisplay.setDirections(response);
} else {
window.alert('Directions request failed due to ' + status);
}
});
}
}
//show error formats incase the location is not found.
function showError(error) {
if (error.code == 1) {
$("#message").html("User denied the request for Geolocation.");
}
else if (error.code == 2) {
$("#message").html("Location information is unavailable.");
}
else if (error.code == 3) {
$("#message").html("The request to get user location timed out.");
}
else {
$("#message").html("An unknown error occurred.");
}
}
}
// Google maper - starting point
google.maps.event.addDomListener(window, 'load', initialize);
</script>
c# jquery
c# jquery
edited Jan 1 at 7:26
Rajesh Pandya
1,3213919
1,3213919
asked Jan 1 at 6:59
Ans SaeedAns Saeed
1
1
Hail The Wall of Unformatted Code! *_*
– iamdanchiv
Jan 1 at 7:25
do you have a div with map id in your .cshtml code.
– Anirudha Gupta
Jan 1 at 9:15
add a comment |
Hail The Wall of Unformatted Code! *_*
– iamdanchiv
Jan 1 at 7:25
do you have a div with map id in your .cshtml code.
– Anirudha Gupta
Jan 1 at 9:15
Hail The Wall of Unformatted Code! *_*
– iamdanchiv
Jan 1 at 7:25
Hail The Wall of Unformatted Code! *_*
– iamdanchiv
Jan 1 at 7:25
do you have a div with map id in your .cshtml code.
– Anirudha Gupta
Jan 1 at 9:15
do you have a div with map id in your .cshtml code.
– Anirudha Gupta
Jan 1 at 9:15
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993610%2fim-having-of-problem-using-map-in-mvc-application-map-is-not-shown-in-view-whi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
draft saved
draft discarded
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
draft saved
draft discarded
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53993610%2fim-having-of-problem-using-map-in-mvc-application-map-is-not-shown-in-view-whi%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hail The Wall of Unformatted Code! *_*
– iamdanchiv
Jan 1 at 7:25
do you have a div with map id in your .cshtml code.
– Anirudha Gupta
Jan 1 at 9:15