Use Google Maps to add map 2 to your website

Source: Internet
Author: User

You need a map HTML element. You can add the content to be displayed when Javascript is unavailable or the browser does not support it. This content can be any HTML, text, or even a static image of the same map. The latter is a better choice to ensure backward compatibility. You only need to make sure that the user map is not notified dynamically anywhere in the text, because it may not be dynamic. Examplegooglemaps.html ( Excerpt) <Div id =" Map "> <P> here You shoshould see an interactive map, but youeither have scripting disabled or your browseris not supported by Google Maps. </P> </div> Make sure that you have given the size of the element in CSS, because otherwise the map will appear irregular. Googlemaps.css # Map { Width: 400px; Height: 300px; Border: 1px solid #999; Margin: 1em; } To add a map to your HTML document, you must add the main Google map as described earlier.CodeThen embed the following script (including the file or put it in Script Element ). Googlemaps. js Function addmap (){ If (gbrowseriscompatible ()){ VaR mapcontainer = Document. getelementbyid ('map '); VaR map = new gmap2 (mapcontainer ); VaR point = new glatlng (51.5623,-0.0934 ); Map. setcenter (point, 13 ); } } Window. onload = addmap; Window. onUnload = gunload; API Of Gbrowseriscompatible () The function checks whether the browser supports Google Maps. If yes, true is returned. After the document is loaded, you can call your own function addmap (). When the document is closed, call the gunload () function provided by the API (because closing the window will trigger the unload event ). The latter is required because the map uses a lot of event processing, which may make MSIE slow due to memory overflow. Tip: In Http://javascript.weblogsinc.com/2005/03/07/javascript-memory-leaks/ You can learn more about MSIE memory overflow and its solution. .

 

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.