Google Maps API Map Application sample sharing _javascript Tips

Source: Internet
Author: User
Tags documentation

Effect (new Firefox test):

Code:

<! Doctype>
<meta http-equiv= "Content-type" content= "Text/html;charset=utf-8" >
<title>google map</title>
<script type= "Text/javascript" src= "Http://maps.google.com/maps/api/js?sensor=false" ></script>
<script type= "Text/javascript" >
function init ()
{
Get Current position
Navigator.geolocation.getCurrentPosition (function (position)
{
var coords = position.coords;
Set the map parameters, setting the latitude and longitude of the current position as the center point
var latlng = new Google.maps.LatLng (coords.latitude,coords.longitude);
var myoptions =
{
Magnification ratio
Zoom:14,
Callout coordinates
CENTER:LATLNG,
Map type
MapTypeId:google.maps.MapTypeId.ROADMAP
};
var map1;
Show Map
Map1 = new Google.maps.Map (document.getElementById (' Map '), myoptions);
Create a tag
var marker = new Google.maps.Marker (
{
POSITION:LATLNG,
Map:map1
});
Set callout window with note text
var Infowindow = new Google.maps.InfoWindow (
{
Content: "Current Position"
});
Open Callout Window
Infowindow.open (Map1,marker);
});
}
</script>
<body onload= "init ()" >
<div id= "Map" ></div>
</body>

Google Maps JavaScript API v3 (reference documentation): Https://developers.google.com/maps/documentation/javascript/basics

Reference document of Baidu Map API: http://developer.baidu.com/map/jsmobile.htm

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.