C# .NET - store lat and long in database - Asked By Odwa on 08-Mar-11 01:20 PM


i've tried using your example of Gmap control and its all good...now i would some help with mine..i want to store my long and lat values in sql server database and when a user enters a query the values are retrieved from my database and displayed in the map control

thanks in advance
dan scan replied to Odwa on 08-Mar-11 01:49 PM
This is a multi-step process and I will outline the steps but to give a complete answer on all of this would be too much for forum response.  If you have trouble with the individual steps ask the a question on the step and I will attempt to answer or someone else will attempt to answere. 

To accomplish this first you will need to get the latlong from google.  This is accomplished by using the google apps javascript call to geocode and address.  The returned javascript object will have the lat and long for the location (if it was found).

The next step in this is the returned object must return the lat and long to your webserver.  Remember the above step took place on the client side.  To do this you must either call a page on your website via postback or with a querysting.  Be for warned I would not write anything to a database that can be sent by an unauthenticated user due to the chance that it can be exploited.  The Page that recieves the information would then write the variables back to the database like any other database write action. 

The final step is to show a point on the map by using the lat and long that you saved to sql server.  The page will need the server side to write the lat and long to a javascript object for process by the client.  Basicly the server would write a literal so that javascript could execute the code when it is on the client.  The client code would use the variable created by the server to create a google apps pinpoint object with the lat and long and then execute the call to google maps with the pinpoint object in the call. 

There is another solution to this that uses some partial postback/AJAX to write the lat and long without doing a postback. 

But like I said in the begining if you need help with one of the above steps let me know and i will try to give more specific help with that step.
harsh shah replied to Odwa on 09-Mar-11 01:57 AM
Hi,
in a google map coding.
add one extra point as a googlePoint.
in a google point add your database latitude and longitude.
and then add this google point to ypur google object.

Like This,

GP1 = new GooglePoint();
              GP1.ID = dsBindData.Tables[0].Rows[i]["Bu"].ToString();
              GP1.Latitude = Convert.ToDouble(dsBindData.Tables[0].Rows[i]["Latitude"].ToString());
              GP1.Longitude = Convert.ToDouble(dsBindData.Tables[0].Rows[i]["Longitude"].ToString());
GP1.IconImage = "1.png";
GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP1);


googlepoint is inbuilt in a google map.

let me know,

Regards,
Harsh Shah
Odwa replied to dan scan on 09-Mar-11 02:52 PM
thanks for the reply..

here is what i have done so far..I have a database with 10 locations and their corresponding lat& long values and an aspx page with a textbox and a button I have also a div tag where the map will be placed ...I would realy appreciate it you can take me through the first step...

thanx again