TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guest User
Tech Writer
2.1k
474.2k
Google maps show current location and state?
Mar 10 2020 7:27 AM
Hi Team
I need some help, my google app does not show correctly my current location, it must show South Africa, Port Elizabeth. But currently these co-ordinates are far from the continent in Africa which is not good for a user to see this, please help.
using
System;
using
System.Collections.Generic;
using
System.Linq;
using
System.Web;
using
System.Web.Mvc;
using
System.Data.SqlClient;
using
System.Configuration;
namespace
eNtsaRegistrationTraining.Controllers
{
public
class
MapsController : Controller
{
// GET: Maps
public
ActionResult GoogleMaps()
{
string
markers =
"["
;
string
conString = ConfigurationManager.ConnectionStrings[
"eNtsaRegistration"
].ConnectionString;
SqlCommand cmd =
new
SqlCommand(
"SELECT * FROM Locations"
);
using
(SqlConnection con =
new
SqlConnection(conString))
{
cmd.Connection = con;
con.Open();
using
(SqlDataReader sdr = cmd.ExecuteReader())
{
while
(sdr.Read())
{
markers +=
"{"
;
markers +=
string
.Format(
"'title': '{0}',"
, sdr[
"Name"
]);
markers +=
string
.Format(
"'lat': '{0}',"
, sdr[
"Latitute"
]);
markers +=
string
.Format(
"'lng': '{0}',"
, sdr[
"Longitute"
]);
markers +=
string
.Format(
"'description': '{0}',"
, sdr[
"Description"
]);
markers +=
"},"
;
}
}
con.Close();
}
markers +=
"];"
;
ViewBag.Markers = markers;
return
View();
}
}
}
@{
ViewBag.Title =
"GoogleMaps"
;
Layout =
null
;
}
<!DOCYTPE html>
<html>
<head>
<meta name=
"viewport"
content=
"width=device-width"
/>
<title>eNtsa Office Location</title>
</head>
<body>
<div id=
"dvMap"
style=
"width: 500px; height: 500px"
>
</div>
<script type=
"text/javascript"
src=
"https://maps.googleapis.com/maps/api/js?key=AIzaSyCKm-dbDykfx2EIjKiZ0Wml8ehHep6K90M"
></script>
<script type=
"text/javascript"
>
var
markers = @Html.Raw(ViewBag.Markers);
window.onload =
function
() {
var
mapOptions = {
center:
new
google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 8,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var
infoWindow =
new
google.maps.InfoWindow();
var
map =
new
google.maps.Map(document.getElementById(
"dvMap"
), mapOptions);
for
(i = 0; i < markers.length; i++) {
var
data = markers[i]
var
myLatlng =
new
google.maps.LatLng(data.lat, data.lng);
var
marker =
new
google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
(
function
(marker, data) {
google.maps.event.addListener(marker,
"click"
,
function
(e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>
</body>
</html>
Reply
Answers (
6
)
Uncaught syntax error handle?
i entered @ in email in behind some value be inserting