Asp.net calls Baidu map API to implement electronic map

Source: Internet
Author: User
http://openapi.baidu.com/map/index.html
Example:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>
<!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">
<Head runat = "server">
<Title> Baidu map API custom Map </title>
<! -- Reference Baidu map API -->
<Style type = "text/css">
Html, body {margin: 0; padding: 0 ;}
. Iw_poi_title {color: # CC5522; font-size: 14px; font-weight: bold; overflow: hidden; padding-right: 13px; white-space: nowrap}
. Iw_poi_content {font: 12px arial, sans-serif; overflow: visible; padding-top: 4px; white-space:-moz-pre-wrap; word-wrap: break-word}
</Style>
<Script type = "text/javascript" src = "http://api.map.baidu.com/api? Key = & amp; v = 1.1 & amp; services = true & gt; </script>
</Head>
<Body>
<! -- Baidu map container -->
<Div style = "width: 697px; height: 550px; border: # ccc solid 1px;" id = "dituContent"> </div>
</Body>
<Script type = "text/javascript">
// Create and initialize map functions:
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 (120.972718, 31.416819); // defines a central point coordinate.
Map. centerAndZoom (point, 17); // 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
}

// 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
</Script>
</Html>

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.