Learn Google Map API in 10 minutes

Source: Internet
Author: User

Http://space.itpub.net/14734354/viewspace-374828

 

 

I played a game a few days ago.GoogleOfMap API, It feels pretty good, very simple. Anyone who has any programming experience can master its main functions within 10 minutes after reading the following tutorials. In addition, I also made a simple small example, if you are interested, please refer to the http://sunjian100.googlepages.com/map.html:]

Step 1:
Apply for a KeyID from the http://www.google.com/apis/maps/signup.html

Step 2:
Add a reference to the MapAPI function library between HTML <title> </title>,
<Script. src = "http://maps.google.com/maps? File = api & v = 2 & key =YourKeyID"Type =" text/javascript "> </script>

Step 3:
Add a DIV named map to any location between HTML <body> </body>,
<Div id = "map" style = "width: 700px; height: 560px" align = "center"> </div>

Step 4:
Add the GMap class instance to the DIV named map,
<Script. type = "text/javascript">
// Create an instance of the GMap class
Var map = new GMap (document. getElementById ("map "));
// Add a control bar
Map. addControl (new GSmallMapControl ());
// Set the display mode to satellite image
Map. setMapType (G_SATELLITE_TYPE );
// Set the longitude and latitude of the center (Shanghai) And zoom coefficient, and display
Map. centerAndZoom (new GPoint (121.4838, 31.2517), 4 );
</Script>

Step 5:
Add 10 randomly marked points,
Var bounds = map. getBoundsLatLng ();
Var width = bounds. maxX-bounds. minX;
Var height = bounds. maxY-bounds. minY;
For (var I = 0; I <10; I ++ ){
Var point = new GPoint (bounds. minX + width * Math. random (),
Bounds. minY + height * Math. random ());
Var marker = createMarker (point, I + 1 );
// Add a tag
Map. addOverlay (marker );
}

Step 6:
Add event response,
Function createMarker (point, number)
{
Var marker = new GMarker (point );

// Show this marker's index in the info window when it is clicked.
Var html = "Marker # <B>" + number + "</B> ";
GEvent. addListener (marker, 'click', function (){
Marker. openInfoWindowHtml (html );});

Return marker;
}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.