Click here to Skip to main content
Click here to Skip to main content
Add your own
alternative version

AJAX Enabled Google Maps ASP.NET Control

, 12 Jul 2010 CPOL
Using the Google Maps API on server side with AJAX support.
GoogleMap.zip
GoogleMapTest
App_Code
vssver2.scc
App_Data
Bin
GoogleMap.dll
vssver2.scc
images
flag1.ico
flag2.ico
marker1.ico
marker2.ico
vssver2.scc
GoogleMap.vssscc
mssccprj.scc
vssver2.scc
GoogleMap
bin
Debug
GoogleMap.dll
GoogleMap.csproj.vspscc
mssccprj.scc
Properties
vssver2.scc
vssver2.scc
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.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Murat Firat
Software Developer (Senior)
Turkey Turkey
Has BS degree on CS, working as SW engineer at istanbul.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 12 Jul 2010
Article Copyright 2010 by Murat Firat
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid