Show Chinese cities and airports in Google Earth (Dynamic kml demo)

Source: Internet
Author: User

Inspired by the last "show contour lines on Google Earth" (image 1, Image 2), I wrote a dynamic implementation to show Chinese cities and airports in Google Earth, the following figure shows the effect. You can also open Google Earth and add an address in the temporary directory: http://www.sharesh.cn/chinacity/index.asp? Or download this kml file: http://files.cnblogs.com/Tangf/ChinaCity.zip (if you open it with a kml file and a bug is found, opening the left chinacity folder for the first time may not be updated, you need to right-click Refresh in the chinacity folder on the left. The specific reason is not clear yet, probablyCodeIf you know anything, please let me know. In fact, kml contains a network link, but it does not allow you to manually operate it)

I originally wanted to create a weather map for Chinese cities and airports, but I have limited capabilities. Now I want to provide a functional preview. I will add it later. I finally understood the principles of eemap's Chinese Navigation plug-in and map spell Earth plug-in (in the website announcement in the lower right corner of the home page), and I was so envious and puzzled.

As for the principle, it is actually very simple, that is, the dynamic generation of kml, No matter what language you use to dynamically generate. I have seen a lot of kml files, but they are all dead files. We cannot add or delete updates. If we want to update the files, we will regenerate the new kml files. Therefore, I am not interested in such files. Now, using dynamic language to generate kml completely solves this problem. Of course, the key here is that GE can use viewrefreshmode to automatically refresh the network link. At the same time, the network link of Google Earth can return the bBox parameter, while the bBox parameter actually reflects the coordinates of the four corners in the current Ge view, then we can dynamically display kml Based on the range, instead of generating all the data at once, and display the data according to the longitude and latitude difference.

OK. Let's use the ASP file in this article and describe the principle of GE using IE. According to the previous paragraph, it is obvious that before the code is run, it is to add a network link kml (for specific kml, see this connection: http://www.sharesh.cn/chinacity/index.asp ?), After the code is run, the specific point data is generated after running GE (see this link: http://www.sharesh.cn/chinacity/index.asp? BBox = 121.5, 31.5,). This is a kml file generated in the range of 121-121.5 longitude and 31-31.5 latitude (in fact, it is almost the central district of Shanghai, you can see airports, cities, and counties. In addition, I also made a hierarchical control. The data is not displayed in the range of 3 degrees or above. Only the "please zoom in the map" is displayed. The city is displayed in the range of 3 degrees and the airport is displayed in the range of 2 degrees, the Level 1 range starts to show the explicit city. The hierarchical display helps the map not to show too much and is too messy. Therefore, if you use bBox =, 30, you can only display the city. In addition, kml also supports map styles. In the first half of kml, we can see the kml code of the style. I made a dedicated file to control the style ). The point is almost over. I don't know whether to make it clear or not. I think it should not be complicated.

A strange phenomenon found throughout the process is that if I don't take the first sentence <? XML version = "1.0" encoding = "UTF-8"?> In the first line, GE cannot open dynamic links, and the dots in the middle of the network link folder are dark purple, for this unintentional error, I rummaged through Google and did not find the answer. The process was difficult: first, because there was no prompt, I could not go to Google keywords, so I want to check the reason through the different states of the GE network link folder, but I also searched Google and looked at all ge kml tutorials, none of them found the description of the different states of GE's network link folder. I was so dizzy that it took me more than an hour. There is no way for me to recall all the code and keep viewing it in the browser. If there is no problem, I can't restart the computer. Finally, I went to the server remotely and asked him to execute it, ge on the server is a low version, but there is an irrelevant prompt after the link is opened, as if it is about XML or something, so Google, there is no kml or GE, however, in an English forum, I probably talked about the above XML to be connected from the beginning. In retrospect, I did return this header to the carriage return, therefore, the xml header is placed in the first line, and the result passes through. The GE network link folder also shows a green normal icon. It takes about two o'clock. Although the problem is solved at the end, I don't know why I can't find any information to solve the problem. I am confused.

I will not summarize it at the end. Write down the plan for the next step.

1. Using the Google weather API to display weather information in cities and airports is actually reading and parsing XML files of weather provided by Google and reorganizing the content into the description.
Some articles about Google weather API recommendations found on GoogleArticle: Google weather API call instructions (you can see how to use this function. I want to use coordinates to generate weather forecasts ), use prototype and Google's weather API for weather forecast (JS and HTML are used at first, you only need to paste the code into the HTML file to see the effect ), google weather API is used to query Weather Forecasts (C # code is provided), and animaonline weather API is used to directly encapsulate the API into DLL, so you can directly use its API, also provides the wince version)

IfProgramIf you are interested, you can write a function to read the weather: getweather (x, y) as string, or call it directly. However, I am also worried that the remote access to weather XML will slow down and affect the entire kml generation speed.

2. If possible, convert ASP to PhP. After all, PHP + MySQL is much more efficient than ASP + access. Besides, if I have a dreamhost space outside of China, it's not a waste. Of course, this article may be a good reference: using PHP and MySQL to create kml

3. Since the entire process has passed, do you want to build an open-source project? There are roughly three parts:
A. database structure. The difference in data structure also has a great impact on the speed, and how to organize the line and area fields added later. Currently, there are only a total of more than 2000 data records, so the use of access does not reflect much efficiency difference.
B. web programs. Similar to a publishing platform, how to make the platform flexible, for example, as long as a certain type of objects, such as how to use search, may be an advanced issue to be considered in the future.
C. Import the raw data to the database. Supports the import of common MIF/mid, GPX, and kml to databases. By the way, you have also completed the mutual import between MIF/Mid and GPX and kml.

If you are interested, you can join us.

4. Use the Google Earth plug-in and API to publish data on the web platform, or use the Google map API to publish data.

I think too much, but it seems that there is still a long way to go. I have been reluctant to use Google map APIs and Google Earth for so many years. Why should I write my thoughts when I am free, however, through this demo, I began to like Google. If there is a combination of projects or applications, it should be a great thing.

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.