Bing map development getting started Lecture 4: Show points of interest

Source: Internet
Author: User
Tags map class

 

Displaying a point of interest on a map is the simplest but most extensive application. For example, a company wants to add a simple map on its home page to display the location of the company. In this lecture, I will briefly introduce the concept of shape: A shape can be a vertex, line, polygon, etc. When initializing a shape object, you can determine the specific shape type based on different input parameters of the initialization function: veshapetype. pushpin, veshapetype. polygon, veshapetype. polyline. Shape initialization example: VaR shape = new veshape (veshapetype. pushpin, map. getcenter (); initialize a shape of the point of interest (pushpin ).In this initialization example, the map. getcenter () method is used to obtain the longitude and latitude of the central position of the current map as the point of interest to be displayed. We can also customize a location: New velatlong (39.9012, 116.3902), that is: VaR shape = new veshape (veshapetype. pushpin, new velatlong (39.9012, 116.3902 ));I will explain the initialization of lines and polygon in subsequent lectures. Next, let's take a look at the specific implementation code for adding a point of interest. We define a function for adding a point of interest: Function addpushpin ()
{
VaR shape = new veshape (veshapetype. pushpin, new velatlong (39.9012, 116.3902 ));
Shape. settitle ('interest point ');
Shape. setdescription ('My points ');
Map. addshape (SHAPE );
}

This function first initializes a shape object as pushpin, and then sets the title and specific description of the point of interest. Finally, call the addshape method of the map class to add a shape on the basic map. Similarly, we need to add a link (or a button) to the html body to allow users to control and add points of interest: <Div> <a href = '# 'onclick = 'addpushpin ();'> add interest points </a> </div>Add the above two pieces of code to the Code for displaying the map in the first lecture. Then you can experience the function of adding points of interest. Of course, sometimes we do not want to manually add a button, but to automatically display a point of interest during map loading. At this time, we need to modify the getmap function: Function getmap ()
{
Map = new vemap ('mymap ');
Map. loadmap ();
Addpushpin ()
}
You can implement these two methods by yourself!

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.