Google map uses XML to load landmarks

Source: Internet
Author: User

1. Apply for a key value for a Google Map

2. Add the following code to the page:

<HTML xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "Content-Type" content = "text/html; charset = UTF-8"/>
<Title> </title>
<SCRIPT src = "http://maps.google.com/maps? File = API & amp; V = 2 & amp; sensor = true & amp; Key = secret & H1 = ZH "type =" text/JavaScript "> </SCRIPT>
<Script language = "JavaScript" type = "text/JavaScript">
VaR map;
VaR geoxml;
Function initialize (){
If (gbrowseriscompatible ()){
Geoxml = new ggeoxml ("http: // www. *****. com/data. xml" + "? RND = "+ math. Random ());
Map = new gmap2 (document. getelementbyid ("map_canvas "));
Map. enablescrollwheelzoom ();
VaR bottomright = new gcontrolposition (g_anchor_bottom_right, new gsize (10, 10 ));
Map. addcontrol (New glargemapcontrol (), bottomright );
Map. addcontrol (New gmaptypecontrol ());
// Coordinate point: (latitude, longitude)
Map. setcenter (New glatlng (39.904, 116.389), 11 );
Map. openinfowindow (Map. getcenter (), document. createtextnode ("Hello, world "));
}
}
</SCRIPT>
</Head>
<Body onload = "initialize ();" onUnload = "gunload ();">
<Div id = "map_canvas" style = "width: 523px; Height: 305px;"> </div>
</Body>
</Html>

 

3. The data. XML data format is as follows:

<? XML version = "1.0" encoding = "UTF-8"?>
<Kml xmlns = "http://earth.google.com/kml/2.1">
<Document>
<Style id = "highlightplacemark">
<Iconstyle>
<Icon>
<Href> http://maps.google.com/mapfiles/kml/paddle/red-stars.png </Icon>
</Iconstyle>
</Style>
<Placemark>
<Name> National theatre </Name>
<Styleurl> # highlightplacemark </styleurl>
<Description>
<! [CDATA [
<H1> CDATA tags are useful! </H1>
<P> <font color = "red"> China is <I> more readable </I> and
<B> easier to write </B> when you can avoid using entity
References. </font> </P>
]>
</Description>
<Point>
<Coordinates>
116.389751, 39.904729
</Coordinates>
</Point>
</Placemark>
</Document>
<! -- Note: When you set the location, the first path is used, and the second latitude is opposite to the setcenter In the JS setting center -->
</Kml>

4. Run, OK

Click here to download the source file:/files/wenming205/google xml.rar

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.