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
scropio gurl
NA
147
99.5k
Show data on map Jquery
Sep 19 2016 5:00 AM
I try to plot data from gridview on map like this
[WebMethod]
public
static
string mapgriddata(string FID,string ObtID)
{
try
{
string result =
""
;
FID = HttpContext.Current.Session[
"FID"
].ToString();
ObID = HttpContext.Current.Session[
"ObID"
].ToString();
Entities w =
new
Entities();
List<spgetdata_ffid_Result> gt = w.spgetdata_ffid(FFID).ToList();
DataTable dt =
new
DataTable();
dt.Columns.Add(
"NO"
, typeof(string));
dt.Columns.Add(
"Longitude"
, typeof(
float
));
dt.Columns.Add(
"Latitude"
, typeof(
float
));
foreach (var t in gt)
{
dt.Rows.Add(t.No, t.Longitude, t.Latitude);
}
string No = HttpContext.Current.Session[
"No"
].ToString();
float
Latitude = Convert.ToSingle(HttpContext.Current.Session[
"Latitude"
]);
float
Longitude = Convert.ToSingle(HttpContext.Current.Session[
"Longitude"
]);
result = DataSetToJSON(dt);
return
result;
}
catch
(Exception)
{
throw
new
Exception();
}
}
jquery
<script type=
"text/javascript"
>
$(function () {
var FID =
'<%=Session["FID"]%>'
;
var ObID =
'<%=Session["ObID"]%>'
;
var No =
'<%=Session["No"]%>'
;
var longi =
'<%=Session["Longitude"]%>'
;
var latit =
'<%=Session["Latitude"]%>'
;
var obj = {};
obj.FID = FID;
obj.ObID = ObID;
obj.No = No;
obj.longi = longi;
obj.latit = latit;
getdata(obj);
return
falase;
});
$(function getdata(obj) {
$.ajax({
type:
"POST"
,
url:
"home.aspx/mapgriddata"
,
contentType:
"application/json;charset=utf-8"
,
data: (data.FFID, data.ObID),
datatype:
"json"
,
async:
true
,
cache:
false
,
success: function (result) {
window.onload = function () {
alert(
"map2"
);
debugger;
var latlng =
new
google.maps.LatLng(24.0895898, 67.0998546);
debugger;
var mapOptions = {
center:
new
google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
debugger;
var infoWindow =
new
google.maps.InfoWindow();
debugger;
var map =
new
google.maps.Map(document.getElementById(
"map_canvas"
), mapOptions);
debugger;
for
(i = 0; i < obj.length; i++) {
var data = obj[i]
var myLatlng =
new
google.maps.LatLng(obj.latlng);
var marker =
new
google.maps.Marker({
position: myLatlng,
map: map,
});
debugger;
(function (marker, obj) {
google.maps.event.addListener(marker,
"click"
, function (e) {
infoWindow.setContent(obj.FID,obj.No,obj.latit,obj.longi);
infoWindow.open(map, obj);
});
})(marker, data);
}
}
},
error: function (error) {
alert(error);
}
});
});
</script>
page load
protected
void
Page_Load(object sender, EventArgs e)
{
mapgriddata(Convert.ToString(Session[
"FID"
]),Convert.ToString(Session[
"ObID"
]));
}
}
but this show error
Object reference not set to an instance of an object.
Reply
Answers (
14
)
Load data to dataGrid
Call ID in jquery