Foros del Web » Programación para mayores de 30 ;) » .NET »

Posicionamiento usando API de Google Map

Estas en el tema de Posicionamiento usando API de Google Map en el foro de .NET en Foros del Web. Buenas gente, Les comento cual es mi duda. He estado mirando los manuales para usar la api de google map para integrar mapas y ubicaciones ...
  #1 (permalink)  
Antiguo 12/03/2012, 03:08
 
Fecha de Ingreso: agosto-2006
Mensajes: 174
Antigüedad: 17 años, 8 meses
Puntos: 2
Posicionamiento usando API de Google Map

Buenas gente,

Les comento cual es mi duda. He estado mirando los manuales para usar la api de google map para integrar mapas y ubicaciones en una aplicacion web que estoy diseñando, pero por ningun lado veo la opcion de ubicar en un mapa segun la direccion y el municipio que recojo dentro de un formulario. Es decir, tengo un webform con una serie de campos para almacenar en base de datos entre ellos esta la calle o la direccion y el municipio, y quiero implementar un boton en el cual "Localize" en el mapa la direccion y el municipio introducido por teclado. Por lo que veo en documentacion de las apis de Google Map no veo un ejemplo en el que se pase por parametro estos valores, sino casi siempre son valores de latitud y longitud.

¿Alguien me podria ayudar?

Muchas gracias
  #2 (permalink)  
Antiguo 30/03/2012, 13:00
Avatar de AnibalDiaz  
Fecha de Ingreso: junio-2011
Mensajes: 65
Antigüedad: 12 años, 10 meses
Puntos: 5
Respuesta: Posicionamiento usando API de Google Map

Hola, hace menos de un año he tenido que hacer lo que pides para el proyecto en el que trabajo... Te transcribo la clase que tuve que crear para usar la API de Google, eso si, está escrita en Delphi Prism (Framework .Net), tendrás que traducirla a c# o vb.net... como prefieras.

<codigo>
namespace Loquesea;

interface

uses
System.Collections.Generic,
System.Linq,
System.Text,
System.Web.UI.WebControls,
System.Xml,
System.Data,
ES.Util;

type
// Cuando haya que implementar la firma de cliente de google y utilizar cuentas de pago.
// http://code.google.com/intl/es-ES/ap...tml#URLSigning
TGoogleMaps = public class
const
//referencia : http://code.google.com/intl/es-ES/ap...ion/geocoding/
GeoCode : String = 'http://maps.google.com/maps/api/geocode/xml?sensor=true&region=es';
//referencia: http://code.google.com/intl/es-ES/ap...on/staticmaps/
StaticMaps : String = 'http://maps.google.com/maps/api/staticmap?zoom={0}&size={1}&sensor=false&center={2 }&format={3}&markers=color:red|label:A|{4}';
GoogleMaps : String = 'http://maps.google.com/maps?q={0}';
private
method CargarPremiumAcount;
method CargarVariables(direccion : String);
method CargarVariables(Latitud : Double; Longitud : Double);
protected
_urlGeoCode : String;
_urlStaticMaps : String;
_urlMapsGoogle : String;
_direccion : String;
_lat : Double;
_lng : Double;
FSucesos: TSucesos;
public
constructor (direccion : String);
constructor (latitud : Double; longitud : Double);

//funciones
function get_MapXML : XmlTextReader;
function get_MapDataSet : DataSet;
function get_MapImage(zoom : Integer; widthPX : Integer; heigthPX : Integer) : String;
function get_MapImage(zoom : Integer; widthPX : Integer; heigthPX : Integer; format : String) : String;
function get_MapExterno : String;
function get_Latitud : Double;
function get_Longitud : Double;
function get_Direccion : String;
end;

implementation

constructor TGoogleMaps(direccion : String);
begin
FSucesos := new TSucesos('Web');
try
CargarPremiumAcount;
_direccion := direccion;
CargarVariables(_direccion);
except
on Ex: Exception do
begin
FSucesos.WriteException(Ex);
raise ex;
end;
end;
end;

constructor TGoogleMaps(latitud : Double; longitud : Double);
begin
FSucesos := new TSucesos("Web");
try
CargarPremiumAcount;
_lat := latitud;
_lng := longitud;
CargarVariables(_lat, _lng);
except
on Ex: Exception do
begin
FSucesos.WriteException(Ex);
raise ex;
end;
end;
end;

method TGoogleMaps.CargarPremiumAcount;
var
Cuenta : String;
Firma : String;
ClienteFirma : String;
begin
try
_urlGeoCode := GeoCode;
_urlStaticMaps := StaticMaps;
_urlMapsGoogle := GoogleMaps;

Cuenta := System.Configuration.ConfigurationSettings.AppSett ings.Item["GoogleMaps.ClientID"].ToString;
Firma := System.Configuration.ConfigurationSettings.AppSett ings.Item["GoogleMaps.Signature"].ToString;

if not String.IsNullOrEmpty(Cuenta) and not string.IsNullOrEmpty(Firma) then
begin
ClienteFirma := '&client=' + Cuenta + '&signature=' + Firma;
_urlGeoCode := _urlGeoCode + ClienteFirma;
_urlStaticMaps := _urlStaticMaps + ClienteFirma;
_urlMapsGoogle := _urlMapsGoogle + ClienteFirma;
end;
except
on Ex: Exception do
begin
FSucesos.WriteException(Ex);
raise ex;
end;
end;
end;

method TGoogleMaps.CargarVariables(direccion : String);
var
ds: DataSet;
begin
try
ds := new DataSet();
ds.ReadXml(new XmlTextReader(string.Format(string.Concat(_urlGeoC ode, '&address={0}'), direccion.Replace(' ','+'))));
_direccion := ds.Tables["result"].Rows[0].Item["formatted_address"].ToString;
_lat := convert.ToDouble(ds.Tables["location"].Rows[0].Item["lat"].ToString);
_lng := convert.ToDouble(ds.Tables["location"].Rows[0].Item["lng"].ToString);
finally
disposeAndNil(ds);
end;

end;

method TGoogleMaps.CargarVariables(Latitud : Double; Longitud : Double);
var
ds: DataSet;
begin
try
ds := new DataSet();
ds.ReadXml(new XmlTextReader(string.Format(string.Concat(_urlGeoC ode, '&latlng={0},{1}'), Latitud, Longitud)));
_direccion := ds.Tables["result"].Rows[0].Item["formatted_address"].ToString;
_lat := convert.ToDouble(ds.Tables["location"].Rows[0].Item["lat"].ToString);
_lng := convert.ToDouble(ds.Tables["location"].Rows[0].Item["lng"].ToString);
finally
disposeAndNil(ds);
end;

end;

function TGoogleMaps.get_MapXML : XmlTextReader;
begin
try
result := new XmlTextReader(string.Format(_urlGeoCode, _direccion.Replace(' ','+')))
except
on Ex: Exception do
begin
FSucesos.WriteException(Ex);
raise Ex;
end;
end;
end;

function TGoogleMaps.get_MapDataSet : DataSet;
var
ds: DataSet;
begin
try
ds := new DataSet();
ds.ReadXml(get_MapXML);
result := ds;
except
on Ex: Exception do
begin
FSucesos.WriteException(Ex);
raise Ex;
end
finally
disposeAndNil(Ds);
end;
end;

function TGoogleMaps.get_MapImage(zoom : Integer; widthPX : Integer; heigthPX : Integer) : String;
begin
try
result := string.Format(_urlStaticMaps , zoom, (widthPX.ToString + 'x' + heigthPX.ToString), _direccion, 'jpg', _direccion);
except
on Ex: Exception do
begin
FSucesos.WriteException(Ex);
raise Ex;
end
end;
end;

function TGoogleMaps.get_MapImage(zoom : Integer; widthPX : Integer; heigthPX : Integer; format : String) : String;
begin
try
result := string.Format(_urlStaticMaps , zoom, (widthPX.ToString + 'x' + heigthPX.ToString), _direccion, format, _direccion);
except
on Ex: Exception do
begin
FSucesos.WriteException(Ex);
raise Ex;
end
end;
end;

function TGoogleMaps.get_Latitud : Double;
begin
result := _lat
end;

function TGoogleMaps.get_Longitud : Double;
begin
result := _lng
end;

function TGoogleMaps.get_Direccion : String;
begin
result := _direccion
end;

function TGoogleMaps.get_MapExterno : String;
begin
result := String.Format(_urlMapsGoogle, _direccion.Replace(' ', '+'))
end;

end.
</codigo>

Como ves, no utilizo ninguna libreria, sino que me creo una cadena String con la URL de Google Maps que te devuelve el mapa.
Existen tambien otras opciones, donde puedes abrir el mapa en un frame y navegar como lo harias en la pagina oficial de google maps.

Espero que te sirva, saludos!
__________________
Si he podido ayudarte, dale al 'Me gustó, ¡gracias!'...

Etiquetas: api, google, map, posicionamiento, aplicaciones
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 13:28.