PHP reads the longitude and latitude of Google Maps

Source: Internet
Author: User

Referring to the online part of the data, they rewrote a convenient access to latitude and longitude information of the class Geo, where latitude and longtitude respectively are latitude and longitude. One of the most important constructors is the incoming place name, which is obtained by WebRequest from the Google Map, and can be easily invoked in a project that contains geographic information, GEO g = new Geo ("Beijing Normal University"), and then G. Latitude and G.longtitude are the latitude and longitude of Beijing Normal University, which are 39.9614580, 116.3692820 respectively. The implementation of GEO is as follows:

Using System;
Using System.Collections.Generic;
Using System.Text;
Using System.Net;
Using System.IO;

Namespace YourNameSpace
{
<summary>
A class for latitude and Longtitude
</summary>
[Serializable]
public class Geo
{
<summary>
Latitude
</summary>
private string _latitude = "";

<summary>
Longtitude
</summary>
private string _longtitude = "";

<summary>
Default constructor
</summary>
Public Geo ()
{

}

<summary>
Construct Geo given latitude and longtitude
</summary>
<param name= "Latitude" ></param>
<param name= "Longtitude" ></param>
Public Geo (String latitude, string longtitude)
{
_latitude = latitude;
_longtitude = Longtitude;
}

<summary>
Construct Geo given name of a place
</summary>
<param name= "Location" ></param>
Public Geo (String location)
{
String output = "CSV";
String url = string. Format (PS tutorial. Google.com/maps/geo?q={0}&output={1 ">http://maps.google.com/maps/geo?q={0}&output={1}" , location, output);
HttpWebRequest request = (HttpWebRequest) webrequest.create (URL);
HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
using (StreamReader sr = new StreamReader (response). GetResponseStream ()))
{
String[] Tmparray = Sr. ReadToEnd (). Split (', ');
_latitude = tmparray[2];
_longtitude = tmparray[3];
}
}

<summary>
Get Latitude (latitude)
</summary>
public string Latitude
{
get {return _latitude;}
set {_latitude = value;}
}

       ///<summary>
       / Get Longtitude (longitude)
       ///</summary>
         public string Longtitude
        {
             get {return _longtitude;}
            set {_longtitude = value;}
       }
   }

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.