Google Maps roadmap to implement code _javascript tips

Source: Internet
Author: User
Tags polyline
Copy Code code as follows:

<script language= "javascript" type= "Text/javascript" >
Add by Ahuinan 2009-8-17
Initialize (23.165613663312594,113.35968017578125)
var map;
var Gdir;
var marker2;
var hasmarker = false;
var hotellatlng = new Glatlng (<%=initxy%>)//Initialize hotel coordinates
var polyline;
var points = [];
POINTS[1] = HOTELLATLNG;
function Initialize () {
if (gbrowseriscompatible ()) {
Map = new GMap2 (document.getElementById ("Divmap"), {googlebaroptions: {showonload:true}});
Gdir = new Gdirections (map);
Map.setcenter (HOTELLATLNG, 9);
Map.addcontrol (New Goverviewmapcontrol ());
Map.addcontrol (New Glargemapcontrol ());

Join Search Box
Map.enablegooglebar ();

Map.enablescrollwheelzoom ();

Create a hotel callout, not drag
var hotelmarker = new Gmarker (new glatlng (<%=initxy%>));
Map.addoverlay (Hotelmarker);

The left mouse button can create a marker,
Gevent.addlistener (Map, "click", Function (OVERLAY,LATLNG,OVERLAYLATLNG) {
if (latlng = null | | hasmarker = = TRUE) {
Return
}
var Greenicon = new Gicon (G_default_icon);
Greenicon.image = ".. /googlemap/green-dot.png ";
Greenicon.iconsize = new Gsize (32,32);
Greenicon.iconanchor = new Gpoint (16,32);
Greenicon.shadowsize=new gsize (56,33);
Marker2 = new Gmarker (Latlng,{draggable:true,icon:greenicon});
Map.addoverlay (MARKER2);

Gevent.addlistener (Marker2, "Dragend", function () {
Points[0] = MARKER2.GETLATLNG ();
Gdir.loadfromwaypoints (points,{"Preserveviewport": true});



})
Gevent.addlistener (Gdir, "Addoverlay", function () {
for (var i=0; I<=gdir.getnumroutes (); i++) {
var originalmarker = Gdir.getmarker (i);
Map.removeoverlay (Originalmarker);
}
Polyline = Gdir.getpolyline ();


Polyline.setstrokestyle ({color: "Red", weight:2,opacity:1});
Map.addoverlay (polyline);

});
Hasmarker = true;
Points[0] = latlng;
Gdir.loadfromwaypoints (points,{"Preserveviewport": true});

})
}
}
Press the Add button
function Add () {
if (points.length = = 1) {
Alert ("No Line, terminate operation");
}else{
Window.opener.document.getElementById ("Txthi_mapmarkdesc"). Value = Window.opener.document.getElementById ("Txthi_ Mapmarkdesc "). value+" \ n "+document.getelementbyid (" Txtname "). value+" | | | " +document.getelementbyid ("Txttype"). value+ "| | | |" +points[0]+ "\ n";
Window.close ();
}
}
Window.onload = function () {
Initialize ()
}
</script>

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.