Google map driving direction source code for their example?

Here’s a very basic example using the v3 API: <!DOCTYPE html> <html> <head> <meta http-equiv=”content-type” content=”text/html; charset=UTF-8″/> <title>Google Maps API v3 Directions Example</title> <script type=”text/javascript” src=”http://maps.google.com/maps/api/js?sensor=false”></script> </head> <body style=”font-family: Arial; font-size: 12px;”> <div style=”width: 600px;”> <div id=”map” style=”width: 280px; height: 400px; float: left;”></div> <div id=”panel” style=”width: 300px; float: right;”></div> </div> <script type=”text/javascript”> var directionsService = … Read more

GoogleMaps v3 API Create only 1 marker on click

var marker; function placeMarker(location) { if ( marker ) { marker.setPosition(location); } else { marker = new google.maps.Marker({ position: location, map: map }); } } google.maps.event.addListener(map, ‘click’, function(event) { placeMarker(event.latLng); }); You have to work on the same marker all the time – do not create new ones. Here you have a global variable marker … Read more

Is it possible to write custom text on Google Maps API v3?

To show custom text you need to create a custom overlay. Below is an example adapted from official Google documentation. You could also use this library for more “stylish” info windows <html> <head> <script type=”text/javascript” src=”http://maps.google.com/maps/api/js?sensor=false”> </script> <script> //adapded from this example http://code.google.com/apis/maps/documentation/javascript/overlays.html#CustomOverlays //text overlays function TxtOverlay(pos, txt, cls, map) { // Now initialize all … Read more

Change map opacity outside circle of Google Maps JavaScript API v3

An example that puts a circular “hole” over New York City (modified from this Google Example): var citymap = {}; citymap[‘newyork’] = { center: new google.maps.LatLng(40.714352, -74.005973), population: 8143197 }; var cityCircle; var bounds = new google.maps.LatLngBounds(); function drawCircle(point, radius, dir) { var d2r = Math.PI / 180; // degrees to radians var r2d = … Read more

How to connect two points in Google map..?

Geocoding is asynchronous. Try something like this (call the second geocoder operation from the call back of the first, use the results of both inside the call back of the second). function createLine() { geocoder = new google.maps.Geocoder(); var latlng = new google.maps.LatLng(7.5653, 80.4303); var mapOptions = { zoom: 8, center: latlng, mapTypeId: google.maps.MapTypeId.ROADMAP } … Read more

Google Maps API map doesn’t appear [duplicate]

Give your map_canvas div a fixed width and height, and your example will work fine: <div id=”map_canvas” style=”width: 500px; height: 400px;”></div> Otherwise, set the height to your html and body as Google does in the API tutorials: <style type=”text/css”> html { height: 100% } body { height: 100%; margin: 0px; padding: 0px } #map_canvas { … Read more