Khush
Khush

Reputation: 877

Google map Markers

I'am trying to insert a google map in my application.

I want to mark the location from source to destination, both of them provided.

I am totally new to JavaScript so please help me with this.

The code that I'am using now is:

   <script type="text/javascript">

        function initialize()
         {
             if (GBrowserIsCompatible()) {
            var map = new GMap2(document.getElementById("map_canvas"));
            map.setCenter(new GLatLng(37.4419, -122.1419), 13);
            var polyline = new GPolyline([
            new GLatLng(37.4419, -122.1419),
            new GLatLng(37.4519, -122.1519)
            ], "#ff0000", 10);
            map.addOverlay(polyline);
            }
        }​​
</script>

How to import the google api related to this code?

Upvotes: 1

Views: 149

Answers (1)

Jiri Kriz
Jiri Kriz

Reputation: 9292

You are using API V2 because of GMap2(...). In this case insert

<script type="text/javascript"
        src="http://maps.google.com/mapsfile=api&amp;v=2&amp;key=KEY&amp;sensor=false">
</script> 

into the <head> section of your HTML document. KEY is the Google API key that you can get from Google. However, it is better to use version V3 of the API. Then you do not need the key. In V3 insert

<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> 
</script>

into the <head> section of your HTML document. See also the Google Map API v3 tutorial. In your document you should have a <div id="map_canvas" ...></div>. The map V3 is created as

 var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); 

Upvotes: 3

Related Questions