Google Maps and jQuery

399 views
Skip to first unread message

Karthik Kastury

unread,
Jun 4, 2010, 12:48:16 PM6/4/10
to Google Maps JavaScript API v3
Hi,

I'm trying to get Google Maps Directions API working with jQuery, and
I have the following code..

<script type="text/javascript">
var directionDisplay;
var directionsService = new google.maps.DirectionsService();
var map;

function initialize() {
directionsDisplay = new google.maps.DirectionsRenderer();
var chicago = new google.maps.LatLng(13.3358866, 74.7711944);
var myOptions = {
zoom:15,
mapTypeId: google.maps.MapTypeId.ROADMAP,
center: chicago
}
map = new google.maps.Map(document.getElementById("map_canvas"),
myOptions);
directionsDisplay.setMap(map);

directionsDisplay.setPanel(document.getElementById("directionsPanel"));
}

function calcRoute() {
var start = "Udupi Railway Station, Udupi, Karnataka, India";
var end = $("#end option:selected");
var request = {
origin:start,
destination:end,
travelMode: google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if (status == google.maps.DirectionsStatus.OK) {
directionsDisplay.setDirections(response);
}
});
}
$(document).ready(function(){ initialize(); $
("#end").change(calcRoute);});
</script>

Where #end is a select list in the HTML.. I'm Using jQuery 1.4.. I'm
not sure as to what is going wrong.. Can you please help me with
this...

Regards
Karthik Kastury
http://twitter.com/coolkarthik88

Chad Killingsworth

unread,
Jun 5, 2010, 7:29:39 PM6/5/10
to Google Maps JavaScript API v3
I'd love to help - but I need an actual link to your page.

Chad Killingsworth

Karthik Kastury

unread,
Jun 6, 2010, 4:31:25 AM6/6/10
to Google Maps JavaScript API v3
I'm trying to get Turn by Turn Directions in my Project.. I have the
from and to values retrieved from the database and stored as a Hidden
Form Field in HTML output.. I want these values to be used and the Map
to be generated..

I'm using a jQuery Plugin which does this but I haven't been able to
get it up and running..

Here's the demo of the plugin : http://mobspot.in/gpsdemo.html
Here's my Implementation : http://mobspot.in/turnbyturn.html


On Jun 6, 4:29 am, Chad Killingsworth

Chad Killingsworth

unread,
Jun 6, 2010, 7:11:52 AM6/6/10
to Google Maps JavaScript API v3
You've got 2 JavaScript errors on the page. One doesn't appear to have
anything to do with the map. The other does - you are missing jQuery's
"$" to call the selector function. Try using this line:

$(function() { $("#map").googleMap().load(); $
('#getdirections').click(); });

Chad Killingsworth
Reply all
Reply to author
Forward
0 new messages