He encontrado este script para obtener coordenadas de una dirección determinada: estaba en texto plano y lo pasé a php.
Código PHP:
<?php
using System;
using System.Net;
namespace GoogleMaps
{
class Program
{
static void Main(string[] args)
{
Coordenadas coordenadas = new Coordenadas("Calle Alcalá 20 Madrid");
coordenadas.ObtenerCoordenadas();
Direccion direccion = new Direccion("40.417915", "-3.698988");
direccion.ObtenerDireccion();
Console.Read();
}
}
class Direccion
{
private string googleKey = "ABQIAAAAV22DtOnxh0_Z7RZc9fr_aRT3ZZAuILe0IBikjNox8YKd4oCEfxRCdjVzSXybiSZaqvjt9hARAV7kHQ";
private string googleUrl = "http://maps.google.com/maps/geo?ll=";
private string Latitud { get; set; }
private string Longitud { get; set; }
public Direccion(string lat, string lon)
{
this.Latitud = lat;
this.Longitud = lon;
}
public void ObtenerDireccion()
{
Uri googleUri = new Uri(String.Format("{0}{1}&output=csv&key={2}", this.googleUrl, this.Latitud + "," + this.Longitud, this.googleKey));
WebClient cliente = new WebClient();
string[] googleCSV = cliente.DownloadString(googleUri).Split('"');
Console.WriteLine("Dirección = " + googleCSV[1]);
}
}
class Coordenadas
{
private string googleKey = "ABQIAAAAV22DtOnxh0_Z7RZc9fr_aRT3ZZAuILe0IBikjNox8YKd4oCEfxRCdjVzSXybiSZaqvjt9hARAV7kHQ";
private string googleUrl = "http://maps.google.com/maps/geo?q=";
private string Direccion { get; set; }
public Coordenadas(string direccion)
{
this.Direccion = direccion;
}
public void ObtenerCoordenadas()
{
Uri googleUri = new Uri(String.Format("{0}{1}&output=csv&key={2}", this.googleUrl, this.Direccion, this.googleKey));
WebClient cliente = new WebClient();
string[] googleCSV = cliente.DownloadString(googleUri).Split(',');
Console.WriteLine("Coordenadas = " + googleCSV[2] + "," + googleCSV[3]);
}
}
}
echo "new Coordenadas";
?>
Gracias y un saludo