?
Solved

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

Posted on 2010-01-13
1
Medium Priority
?
807 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
This tutorial walks through the best practices in adding a local business to Google Maps including how to properly search for duplicates, marker placement, and inputing business details. Login to your Google Account, then search for "Google Mapmaker…
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

777 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