Php read google map latitude and longitude-PHP source code

Source: Internet
Author: User
Ec (2); based on some online materials, I have rewritten a Geo class that is convenient for obtaining Latitude and longitude information. Latitude and Longtitude are Latitude and longitude respectively. The most important constructor is to pass in the place name and obtain the latitude and longitude values from GoogleMap through Webrequest. GeognewGeo (& quot; beijing Normal University & quot;); then g. latitude and g. longt script ec (2); script

Based on some information on the Internet, I modified a Geo class that is convenient for obtaining Latitude and longitude information. Latitude and Longtitude are Latitude and longitude respectively. The most important constructor is to pass in the place name and obtain the latitude and longitude values from Google Map through Webrequest. It can be conveniently called in projects that contain geographical location information, that is, Geo g = new Geo ("Beijing Normal University"); then g. latitude and g. longtitude is the latitude and longitude of Beijing Normal University. They are 39.9614580 and 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
{
///


/// A class for latitude and longtitude
///
[Serializable]
Public class Geo
{
///
/// Latitude
///
Private string _ latitude = "";

///


/// Longtitude
///
Private string _ longtitude = "";

///


/// Default constructor
///
Public Geo ()
{

}

///


/// Construct geo given latitude and longtitude
///
///
///
Public Geo (string latitude, string longtitude)
{
_ Latitude = latitude;
_ Longtitude = longtitude;
}

///
/// Construct geo given name of a place
///
///
Public Geo (string location)
{
String output = "csv ";
String url = string. Format ("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];
}
}

///


/// Get latitude (latitude)
///
Public string Latitude
{
Get {return _ latitude ;}
Set {_ latitude = value ;}
}

///


/// Get longtitude (longitude)
///
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.