Use the Google Maps API to add and delete lines on a map

Source: Internet
Author: User

 

Load Map
Function load ()
{
// Checks whether the current browser supports Google Maps.
If (gbrowseriscompatible ())
{
Map = new gmap2 (GetObject ('map '));
// Add built-in controls to the map

Map. addcontrol (New gmaptypecontrol ());

// The pan and zoom controls (upper left corner ),
Map. addcontrol (New glargemapcontrol ());

// Scale controls (lower left corner ),
Map. addcontrol (New gscalecontrol ());

// Thumbnail Control (lower right corner)
// Map. addcontrol (New goverviewmapcontrol ());

Map. enabledoubleclickzoom ();
Map. enablescrollwheelzoom ();

// Move the view to Shenzhen
Map. setcenter (New glatlng (22.550000, 114.030000), 12 );
}
}

 

Add line

Function addpolyline ()
{

VaR polyline = new gpolyline ([New glatlng (22.5500, 114.0300), new glatlng (22.5600, 114.0400), new glatlng (22.5700, 114.0500)], "# ff0000", 3 );
Map. addoverlay (polyline );

}

Strikethrough

Function removepolyline ()
{
Map. clearoverlays () // removeoverlay (); // or gmap2.clearoverlays ();

}

 

You can also use the following method to add a line:
Function addpolyline ()
{
VaR points = [];
Points. Push (New glatlng (22.5500, 114.0300 ));
Points. Push (New glatlng (22.5600, 114.0400 ));
Points. Push (New glatlng (22.5700, 114.0500 ));
Points. Push (New glatlng (22.5800, 114.0600 ));
Points. Push (New glatlng (22.5900, 114.0700 ));

VaR polyline = new gpolyline (points, "# ff0000", 3 );
Map. addoverlay (polyline );
}

 

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.