Simple use of google map API, google map api

Source: Internet
Author: User

Simple use of google map API, google map api
<Div id = "contact_container" style = "width: 700px; height: 600px;"> </div>
<Script type = "text/javascript">
Function initialize (){
Var myLatlng = new google. maps. LatLng (39.95745, 116.32764 );
Var myOptions = {
Zoom: 18,
Center: myLatlng,
MapTypeId: google. maps. MapTypeId. ROADMAP
}
Var map = new google. maps. Map (document. getElementById ("contact_container"), myOptions );
Var marker = new google. maps. Marker ({
Position: map. getCenter (),
Map: map,
Title: 'caas'
});
}

Function loadScript (){
Var script = document. createElement ("script ");
Script. type = "text/javascript ";
Script. src = "http://maps.google.com/maps/api/js? Language = en & sensor = false & callback = initialize ";
Document. body. appendChild (script );
}

Window. onload = loadScript;
</Script>
How to call Google map APIs

After reading this article, I still read the official materials: developers.google.com/maps/mobile-apps.
 
C # function call baidu or google map API

I did a simple job before, but it seems that html code cannot be displayed. Stick the main JavaScript code and give it to you.

Function initMap (){
CreateMap (); // create a map
SetMapEvent (); // sets map events
AddMapControl (); // Add a control to the map
}
// Create a map function:
Function createMap (){
Var map = new BMap. Map ("dituContent"); // create a map in the Baidu Map container
Var point = new BMap. Point (); // defines a central point coordinate.
Map. centerAndZoom (point, 5); // set the center and coordinates of the map and display the map in the map container
Window. map = map; // store the map variable in the global
}

// Search for map Functions
Function searchMap (){
Var local = new BMap. LocalSearch (map ,{
RenderOptions: {map: map}
});
Map. removeOverlay ();
Var key = document. getElementById ("Index"). value;
Local. search (key );
}
// Map event setting function:
Function setMapEvent (){
Map. enableDragging (); // enables the map drag event. It is enabled by default (not writable)
Map. enableScrollWheelZoom (); // enables zoom in and out of map Rollers
Map. enableDoubleClickZoom (); // enables double-click mouse amplification. It is enabled by default (not writable)
Map. enableKeyboard (); // enable the keyboard to move the map from top to bottom
}
// Map control add function:
Function addMapControl (){
// Add a zoom control to the map
Var ctrl_nav = new BMap. NavigationControl ({anchor: BMAP_ANCHOR_TOP_LEFT, type: BMAP_NAVIGATION_CONTROL_LARGE });
Map. addControl (ctrl_nav );
// Add a thumbnail control to the map
Var ctrl_ove = new BMap. OverviewMapControl ({anchor: BMAP_ANCHOR_BOTTOM_RIGHT, isOpen: 1 });
Map. addControl (ctrl_ove );
// Add a scale control to the map
Var ctrl_sca = new BMap. ScaleControl ({anchor: BMAP_ANCHOR_BOTTOM_LEFT });
Map. addControl (ctrl_sca );
}
InitMap (); // create and initialize a map

... Remaining full text>


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.