Several other issues that need to be concerned:
The sample code above is just to show a simple map of the nature of the test, so a lot of code that is not necessary for the moment is removed, if you need to create a map that has good compatibility and can be published to your own website, pay attention to the following issues:
To ensure compatibility, Google recommends using XHTML to define HTML pages for displaying maps. Therefore, you need to declare the XHTML doctype at the top of the page, and declare the XHTML namespace in HTML.
<! Doctype HTML public "-// W3C // dtd xhtml 1.0 strict // en"
Http://www.w3.org/TR/xhtmll/DTD/xhtmll-strict.dtd>
<HTML xmlns = "http://www.w3.org/1999/xhtml">
Of course, it is best for your page code to comply with the XHTML syntax rules. Compared with the latest html version, the XHTML syntax rules can be summarized as follows:
Each element of HTML, Head, title, and body must have only one root element of HTML;
Do not use simplified attributes. You must use the "name = 'value'" format;
Both the Tag Name and attribute name Use lowercase letters, and the attribute value must be enclosed in quotation marks;
Tags must be closed and cannot be cross-nested;
Use the ID attribute instead of the name attribute to obtain the element;
To be compatible with the latest version of Internet Explorer, you must add a VML namespace statement to the HTML tag to display the line in the map correctly in IE.
<HTML xmlns = "http://www.w3.org/1999/xhtml" xmlns: V = "urn: Schemas-Microsoft-com: VML">
This is easy to ignore. As a result, the line in IE cannot be normally displayed. Therefore, we will emphasize this point in a single column.
For general browser compatibility checks, map API provides a global method gbrowseriscompatible () to ensure that map APIs run in compatible browsers, I have not found the latest list of compatible browsers. The Google document provides a list of ancient times, so I should leave it alone, there is no problem in running the map API in our currently common Firefox, ie, Safari, and opera browsers.
Here we will only talk about the use of the gbrowseriscompatible () method:
We can also see from the name that the gbrowseriscompatible () method returns a Boolean value. Therefore, we place the starting point of the map operation in the judgment block of the return value of this method, as shown in:
If (gbrowseriscompatible ()){
// Start creating and operating the map
} Else {
// Define your handling of this exception here if necessary
}
Of course, in your own code, you still need to implement compatible code for different browser environments. Here gbrowseriscompatible () it only ensures that the map API class library runs in its compatible environment.
4. register the Google map API key of the website on which you want to publish the page, and replace your_api_key in the sample code.
5. To ensure that your page can be quickly loaded and correctly displayed in any available network environment, we recommend that you define the onload method of the Body element and start your JS actions in the onload method. At the same time, put the script tag that reads the map API into the head element, and put your own JavaScript code block behind the body tag for definition. If you are familiar with the loading sequence of browsers, you do not have to follow the rules I have mentioned and define the Javascript declaration sequence as you think.
6. In order to avoid Memory leakage (especially for IE browsers) of DOM elements on pages referenced in Javascript, you need to use the gunload () defined in the map API () method is the onUnload method of your body element, and it is best to remember this as a required rule. However, the gunload () method is not a universal key to avoid Memory leakage. Therefore, you must avoid Memory leakage in your code.
7. To display Chinese characters normally on the page, you need to define the character set of the page as UTF-8.