Google Maps javascript API V3 load maps by address

Source: Internet
Author: User

As follows:

 

JavaScript code:

<! Doctype HTML public "-// W3C // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <HTML xmlns = "http://www.w3.org/1999/xhtml"> 



New encapsulated version:
VaR map; var geocoder = new Google. Maps. geocoder ();/***-25.363882, 131.044922 * initial map */
Function initialize (LAT1, lng1, zoom, canvas_div ){
VaR mylatlng = new Google. Maps. latlng (LAT1, lng1 );
VaR myoptions = {
Zoom: Zoom,
Center: mylatlng,
Maptypeid: Google. Maps. maptypeid. Roadmap
}
Map = new Google. Maps. Map (document. getelementbyid (canvas_div), myoptions );
}
// Function placemarker (latlng, HTML ){
VaR marker = new Google. Maps. Marker ({
Position: latlng,
Map: map,
Cursor: "1 ",
Flat: True,
Draggable: false,
Clickable: True,
Visible: True
});
Map. setcenter (latlng );
VaR infowindow = new Google. Maps. infowindow ({content: HTML });
// Infowindow. setposition (latlng); infowindow. Open (MAP, marker );
}
// Obtain the Coordinate Function codeaddress (latitude, longpolling, HTML, address, fun ){
If (0 = latitude | 0 = longpolling ){
If (geocoder ){
Geocoder. geocode ({'address': Address}, function (results, status ){
If (status = Google. Maps. geocoderstatus. OK ){
Fun (results [0]. Geometry. Location, HTML );
} Else {
Fun (latlng, HTML );
//. Return false; // alert ("geocode was not successful for the following reason:" + status );}
});
}
} Else {
Placemarker (new Google. Maps. latlng (latitude, longpolling), HTML );
}
}

Call:

<SCRIPT type = "text/JavaScript" src = "http://maps.google.com/maps/api/js? Sensor = false "> </SCRIPT>
<SCRIPT src = "scripts/GMAP. js" type = "text/JavaScript"> </SCRIPT>
$ (Function (){
Initialize ('0. 000000 ', '0. 000000', 16, 'map _ canvas ');
VaR html = 'xxx ';
Codeaddress ('0. 000000 ', '0. 000000', HTML, ADDR, placemarker );
});

 

Baidu:

The request interface has four parameters:
The values corresponding to from and to are: 0 real coordinates, 2google coordinates, and 4baidu coordinates.
From: The transformed Coordinate System
To: Convert to this coordinate system
X: longitude
Y: latitude
// GPS longitude and latitude to Baidu coordinates // GPS: http://api.map.baidu.com/ag/coord/convert? From = 0 & to = 4 & X = LNG & Y = lat // Google: http://api.map.baidu.com/ag/coord/convert? From = 2 & to = 4 & X = LNG & Y = lat // example: http://api.map.baidu.com/ag/coord/convert? From = 0 & to = 4 & X = 116.397428 & Y = 39.90923 string S = BIND ("mte2ljqxmda0otuwnty2", "mzkuote2otc5nte5odcz"); // 116.41004950566, 39.916979519873 protected string BIND (string a, string B) {return base64decode (A) + "," + base64decode (B);} public static string base64encode (string astr) {return convert. tobase64string (encoding. utf8.getbytes (astr);} public static string base64decode (string abase64) {return encoding. utf8.getstring (convert. frombase64string (abase64 ));}

 

Related Article

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.