Google Map API in conjunction with jquery (1)--control, listener

Source: Internet
Author: User

Google Maps JavaScript API allows you to use Google Maps on your own Web pages. Before using the API, you should apply for an API key, request API Key please: http://code.google.com/apis/ Maps/signup.html. This assumes that the key you have obtained is: ABQIAA.

The acquisition of jquery is no longer burdensome, and there are many introductions to jquery on the web.

We then use the jquery and Google Maps JavaScript APIs to combine the interesting map effects of Google Map to the goal of familiarizing ourselves with the Google Maps JavaScript API.

Let's start with a Hellochina:

(1) Writing HTML code in an HTML file:

Map.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps 与 JQuery结合使用</title>
<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=ABQIAA" type="text/javascript"></script>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="map.js"></script>
<body>
<div id="map" style="top:100px;left:300px;width: 600px; height: 400px"></div>
<div id="message"></div>
</body>

(2) in the JS file to write JS code

Map.js

$(document).ready(function()
{
//检查浏览器兼容性
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
map.setCenter(new GLatLng(36.94, 106.08), 4);//中国的经纬度以及地方放大倍数
map.setMapType(G_SATELLITE_MAP);
//document卸载时触发
$(window).unload(function (){
$('.').unbind();
GUnload();
});
}else
{
alert('你使用的浏览器不支持 Google Map!');
}
});

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.