Reputation: 450
I am trying to write a code in c# which retrieves data from database and passes that data to javascript (within a loop one record at a time) for processing via google map api. That javascript returns a list of string which I use to carry out further processing and save to db via c#.
Until now I realized that javascript function just gets called one time even if we write it in the loop. Moreover I even don't have any idea how I will return list of string from javascript and use that inside c#.
I am badly stuck at this. Can you please suggest a good and effective method?
Thank You.
Here is the code which I have written but it didn't worked.
foreach (LocationDataPacket d in l)
{
if (d.cellPhoneGPSData == current_cell)
{
lat1 = lat2;
long1 = long2;
lat2 = d.Lat;
long2 = d.Long;
ScriptManager.RegisterStartupScript(this, GetType(), "check", "check("+d.ID+");", true);
}
else
{
lat2 = d.Lat;
long2 = d.Long;
current_cell = d.cellPhoneGPSData;
}
}
Upvotes: 1
Views: 5868
Reputation: 11
I had a similar problem with Google Maps and found a solution in using PageMethods which returned all the data at the same time in a json and then I put the markers on the map.
In my case the next call I made to collect data I cleared the previous points on the map and put up the next collection by every call (this since the user could make another selection that changed all the markers) but of course it's possible to just add new markers if it's possible in your case.
Upvotes: 0
Reputation: 4402
I googled "accessing google maps api from .net client" and it led me to the Google APIs Client Library for .NET:
https://developers.google.com/api-client-library/dotnet/
I'm assuming this will allow your .net program (might not even have to run on an asp.net server depending on your requirements) to become a direct google map API client so you can do all this processing locally.
Edit: Addressing your original question, in order to get data from the client back to your web server the client needs to post back the information. This question seems to cover that pretty well: Send javascript variables to server-side ASP .NET . However I would not recommend attempting this based on what you said you wanted to accomplish. I'd try the .NET client library for the API first.
Upvotes: 1
Reputation: 145
in this link you can find many method for transfer value from back c# to javascript
C# to javascript value transfer methods
Upvotes: 0
Reputation: 145
<script runat="server">
foreach (LocationDataPacket d in l)
{
if (d.cellPhoneGPSData == current_cell)
{
lat1 = lat2;
long1 = long2;
lat2 = d.Lat;
long2 = d.Long;
ScriptManager.RegisterStartupScript(this, GetType(), "check", "check("+d.ID+");", true);
}
else
{
lat2 = d.Lat;
long2 = d.Long;
current_cell = d.cellPhoneGPSData;
}
}
</script>
write these code into head Tag.. hope this will help u.
Upvotes: 0