Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Saving Marker Locations into the database(SQLServer) in Google Map

Posted on 2010-01-13
1
Medium Priority
?
842 Views
Last Modified: 2012-05-08
I am pretty new to web programming especially to Google Api for Maps. Is it possible to save the geocodes or latitude /logitude values of markers that are created in the database. This is because the next time the page loads the Markers should be in the same position as last left by the user. I dont mean cache here.
Any sample code for this purpose will be greatly appreciated.
0
Comment
Question by:rupvis
1 Comment
 
LVL 11

Accepted Solution

by:
asafadis earned 2000 total points
ID: 26312606
I found a pretty straightforward post from someone else in your same situation:
http://stackoverflow.com/questions/1746230/google-maps-add-a-marker-to-map-then-store-latitude-and-longitude-in-ruby-on-rai

In his case, he needed a Ruby On Rails solution, however the code is simple and self-explanatory enough for you to interpret it and "translate" it into JSP.

NOTE: JavaScript doesn't have access to the database.  In fact it doesn't know what a database is!  You'll have to make an AJAX call to a JSP page that will receive some parameters and perform the necessary database functions.  The guy in the post recommends jQuery... so do I!

Your script should look something like:
/* JAVASCRIPT */

draggable_marker = new GMarker(new GLatLng(42.6976489, 23.3221545), {draggable : true,title : "Place this marker to your location");

GEvent.addListener(draggable_marker, 'dragend', function() {  
    savePosition(draggable_marker);
});

function savePosition(marker) {
    var title = marker.getTitle();
    var lat   = marker.getLatLng().lat();
    var lng   = marker.getLatLng().lng();
    
    // jQuery Part
    $.ajax({
        type: "GET",
        url: "someJSPPageToDoDatabaseFunctions.jsp",
        data: "title=" + title + "&lat=" + lat + "&lng=" + lng,
        success: function(msg){
            alert( "Data Saved: " + msg );
        }
    });
}

/* someJSPPageToDoDatabaseFunctions.jsp */
I'm not that familiar with JSP, but write a script that will interpret a URL like:
    someJSPPageToDoDatabaseFunctions.jsp?title=FootLocker&lat=42.6976489&lng=23.3221545

Once you catch these values, save them!

Open in new window

0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction This article is designed to assist GIS (Geographic Information System) and GPS (Global Positioning System) developers using ESRI ArcGIS and other spatial information management systems.   For the uninitiated the concept of projectio…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

577 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question