Small Example of Google map API

Source: Internet
Author: User

Played a game a few days ago {
Tagshow (event, 'Google ');
} "Href =" javascript:; "target =" _ Self ">Google{
Tagshow (event, 'map ');
} "Href =" javascript:; "target =" _ Self ">Map{
Tagshow (event, 'api ');
} "Href =" javascript:; "target =" _ Self ">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 ({
Tagshow (event, '% C9 % CF % Ba % A3 ');
} "Href =" javascript:; "target =" _ Self ">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.