|
using System;
using System.Collections.Generic;
using System.Text;
using System.Globalization;
namespace GoogleMap
{
public enum MapTypes { ROADMAP, SATELLITE, HYBRID, TERRAIN }
public class MapInfo
{
private double latitude;
private double longtitude;
private int zoom;
private MapTypes mapType;
public double Latitude
{
get { return latitude; }
set { latitude = value; }
}
public double Longtitude
{
get { return longtitude; }
set { longtitude = value; }
}
public int Zoom
{
get { return zoom; }
set { zoom = value; }
}
public MapTypes MapType
{
get { return mapType; }
set { mapType = value; }
}
public override string ToString()
{
return
string.Format("lat:{0}|lng:{1}|zoom:{2}|maptype:{3}",
latitude.ToString().Replace(",", "."),
longtitude.ToString().Replace(",", "."),
zoom.ToString(),
mapType.ToString())
;
// return base.ToString();
}
public static MapInfo FromString(string MapInfoStr)
{
string extra1 = null, extra2 = null, extra3 = null;
return FromString(MapInfoStr, ref extra1, ref extra2, ref extra3);
}
public static MapInfo FromString(string MapInfoStr, ref string extra1, ref string extra2, ref string extra3)
{
//if(Regex.IsMatch(MapInfoStr,"lat:.+|lng")
if (!MapInfoStr.Contains("lat:") || !MapInfoStr.Contains("lng:")
|| !MapInfoStr.Contains("zoom:") || !MapInfoStr.Contains("maptype:"))
return null;
//extra1 = null; extra2 = null; extra3 = null;
CultureInfo ciTR = new CultureInfo("tr-TR");
MapInfo inf = new MapInfo();
string[] infArr = MapInfoStr.Split('|');
string maptypeStr = null;
foreach (string param in infArr)
{
string[] paramArr = param.Split(':');
if (paramArr.Length == 2)
{
switch (paramArr[0])
{
case "lat":
inf.latitude = double.Parse(paramArr[1].Replace(".", ","), ciTR.NumberFormat);
break;
case "lng":
inf.longtitude = double.Parse(paramArr[1].Replace(".", ","), ciTR.NumberFormat);
break;
case "zoom":
inf.zoom = int.Parse(paramArr[1]);
break;
case "maptype":
maptypeStr = paramArr[1];
break;
case "extra1":
extra1 = paramArr[1];
break;
case "extra2":
extra2 = paramArr[1];
break;
case "extra3":
extra3 = paramArr[1];
break;
default:
break;
}
}
}
switch (maptypeStr.ToLower(new CultureInfo("en-US")))
{
case "satellite":
inf.mapType = MapTypes.SATELLITE;
break;
case "roadmap":
inf.mapType = MapTypes.ROADMAP;
break;
case "hybrid":
inf.mapType = MapTypes.HYBRID;
break;
case "terrain":
inf.mapType = MapTypes.TERRAIN;
break;
default:
inf.mapType = MapTypes.ROADMAP;
break;
}
return inf;
}
public MapInfo Copy()
{
MapInfo inf = new MapInfo();
inf.latitude = this.latitude;
inf.longtitude = this.longtitude;
inf.mapType = this.mapType;
inf.zoom = this.zoom;
return inf;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
Has BS degree on computer science, working as software engineer in istanbul.