Overview of Geo-Location

Source: Internet
Author: User
Tags geoip database maxmind

Online Map is already a common application, and Google Map can even be used as a driving navigator. However, the implementation of these applications involves a lot of hard work, just positioning your current location, there are a lot of technologies. Fortunately, today, on your Web site, you can get a geographical location of a user through just a few lines of code, this article describes various geographic positioning technologies used in the Web.

Obtain the geographical location information of a user using an IP address

The Internet is just a huge network. Each computer on the Internet corresponds to an IP address. Through this IP address, we can know where this user is located. We can query the Maxmind GeoIP database to obtain the IP address, maxmind also provides a JavaScript interface for you to implement this function on your website.

 

There is a problem with this method (demonstration), that is to say, the geographic location information of your obtained IP address may not be very accurate, because this IP address is assigned to you by your ISP, what you get is actually the ISP's geographic location. In addition, if you use VPN, you may actually get a location more than 108,000 miles away.

Obtain the geographical location of a user using W3C Geo API

Security and privacy are another difficult issue to obtain users' geographic locations through IP addresses. After all, not every user is willing to know their geographic location information, many technologies have been developed. Google Gears has a Geo-Location service. Plazes helps you save your Location, and Yahoo Fire Eagle is one of the most popular technologies. However, the common problem with these technologies is that they require users to either install a plug-in or access a specific Web service, which is a bit of a hassle.

W3C has a Geo-Location API to help browser manufacturers integrate the geographic information function in browsers. Firefox 3.5 or above supports W3C Geo-LocationAPI, and Safari on the iPhone (OS3.0 or above is required ). Users who need to query their geographic locations through the browser will display a dialog bar in the browser and request your authorization. As shown in:

The following code requests to use this function:

The following Demonstration demonstrates the differences between the above two Geographic Information Acquisition Technologies. We can see that they have many differences in measuring the geographical location of users.

Convert longitude/dimension to place name

It converts longitude/dimension information into a status called anti-Geo-Location. There are many such services available on the network, the most famous of which is the geo-names Web service, however, it still has several problems. For example, its results are centered on the United States. Another one is free to use and supports global information, but a small number of people who know the service come from a surprising place, Flickr. Flickr. places. the findByLatLon service returns place names based on the longitude and latitude information. You can try it using app explorer. However, the simplest method is to use Yahoo Query Language (YQL ). YQL looks like this:

Using the YQL query language, you can obtain data in XML or JSon format. This is an example of using this query language in JavaScript:

Combined with the preceding example, with the help of the anti-Geo-Location query, we get the detailed Location name information:

Latitude and longitude

 

Although longitude and latitude can be used to locate a location on the earth, latitude and longitude are sometimes prone to ambiguity. To solve this problem, Yahoo and Flickr (which Twitter will soon support) support another method, it is called Where On Earth Identifier (WOEID ). With this method, we can easily obtain the Flickr image from a region.

In this way, a few JavaScript codes can display images from a specified geographic location:

These codes can also be packaged into functions. The following code will show 10 photos from Paris. You can try it on your own on the YQL console:

Automatically mine geographic information in text content

If you want to get a piece of text or the geographic location information of a place name mentioned in a webpage content, Yahoo provides a good service called Placemaker. Obtain a developer key from Yahoo to use the service. You only need to create a publishing form and publish ithttp://wherein.yahooapis.com/v1/document, Publish the Developer Key with appid, publish the text to be queried with documentContent, publish the text type with documentType, and define the returned data type with outputType, as shown below:

You can also use PHP to call this API and set the output data format. Here, we also use PlaceMaker to design the GeoMaker service. Simply enter the text or URL and select a location to return to the map.

Because PlaceMaker can also be used in JavaScript through YQL, we can use the same function through several client scripts:

You need three things: A piece of text in an HTML object that contains a geographical location, a Google Maps API Key (application), and the following code:

Insert a map into a webpage

There are many online Maps. Google Map is one of the leaders. In addition to Google, Yahoo, and Microsoft, it provides Map services and an Open Map service called Open Street Maps, it was used in the last earthquake relief in Haiti. The easiest way to insert an interactive map into a webpage is to use Mapstraction, which provides a JavaScript library and has published a good introduction Article 24 ways. If you only want to put your map on the webpage to indicate your location, and do not want to use too much JavaScript, Google static maps API is the best choice, it will generate a static map, the following code inserts a static map into your webpage (Google also provides a tool for creating a static map ):

 

International Source: http://www.smashingmagazine.com/2010/03/08/entering-the-wonderful-world-of-geo-location/

Chinese compiling Source:Ruishang enterprise CMSWebsite content management system official website

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.