Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

Online Geocoder with interactive Map

4.72/5 (10 votes)
29 Jun 2015CPOL3 min read 43.5K  
Web app to find geographical coordinates and apply them to the Bing Map

Introduction

Geographic coordinates provide the unified way to identify any place on Earth. City streets could change their names and numbers, but the universal coordinate system, free of daily vanities and challenges of time, presents perpetual time-invariant values on a planetary level. Geographic coordinates system in general includes longitude, latitude and elevation (height), but the most used are the first and the second ones, namely longitude/latitude. They could be presented either in degrees:minutes:seconds (so-called DMS) format or decimal degrees (DD) format (used in the application).

Geographic coordinates could be obtained via global positioning system (GPS) devices, but this technique requires the physical presence at the point of interest. As an alternative, the geocoding software applications (or simply geocoder, or geo-locator) could be used to convert the postal addresses to the corresponding longitude/latitude pairs. Such geocoder has been built in conjunction with interactive online Map powered by Microsoft Bing™ technology, allowing different views, panorama and zooming; it is available online totally free at [1], serving both practical and didactic purposes (no registration is needed).

Usage

The usage is rather straightforward and intuitive: in order to obtain the longitude/latitude information and the map of the geographic point of interest, either in the US, or worldwide follow the steps described below:

  1. Open web browser and navigate it to the Geocoder
  2. Enter the postal address into the search box and click on the "Find" screen button. Note: places in the US could be identified just by their ZIP (postal) code
  3. Upon the completion of screen reload, which could take up to several seconds, you should be able to see the longitude/latitude of the point of interest and corresponding Bing map. You could select the preferred map view modes (road, aerial or bird’s eyes), adjust zoom level (from 1 to 19) and perform the panoramic function

Multilingual support

Online geocoder has multi-lingual capabilities, accepting search queries in many foreign languages: Spanish, German, Italian, French, Russian, Greek, etc. Below are sample test results, corresponding to the world landmarks, entered in a search query in the language of origin:

  • Metropolitan Museum, New York |  Lat: 40.779437/Lon: -73.963244
  • Grand Central Terminal, NY | Lat: 40.752726/Lon: -73.977229
  • Colosseo, Roma | Lat: 41.89021/Lon: 12.492231
  • Ακρόπολη Αθηνών | Lat: 37.971532 /Lon: 23.725749
  • Brandenburger Tor, Unter Der Linden | Lat: 52.516275 /Lon: 13.377704
  • Champs-Elysées, Paris | Lat: 48.869576/Lon: 2.30825
  • Eiffel Tour, Champs De Mars | Lat: 48.85837/Lon: 2.294481
  • Museo del Prado, Madrid | Lat: 40.413782/Lon: -3.692127
  • Cappella Sistina, Rome |  Lat: 41.902947/Longitude: 12.454484
  • Музей Эрмитаж, Санкт Петербург | Lat: 59.939832/Lon: 30.31456

Demo

The following screenshots demonstrate the usage of Multilingual Geocoder with interactive Bing Map (see Fig 1-4):

Image 1

Fig.1 Columbus Circle NY, Geo Coordinates (the distances from NY City are calculated from this point)

 

Image 2

Fig.2 Columbus Circle NY on the Bing Map, sample screenshot (Aerial view mode)

 

Image 3

Fig.3 Coordinates of the Brandenburg Gate, Berlin, Germany

 

Image 4

Fig.4 Brandenburg Gate on Bing Map (Bird's eye view mode)

Points of Interest

Calculation of the great-circle (orthodromic) distance between two geo-points on the Earth surface is the general GIS task. It can be acomplished by using Spherical Earth projection algorithm listed below [2]:

C#
/*****************************************************************************************
Module           :  GIS.cs
Description      :  Calculate distance between two geo-points on surface
*****************************************************************************************
Author           :  Alexander Bell
Copyright        :  2011-2015 Infosoft International Inc
*****************************************************************************************
DISCLAIMER       :  This Module is provided on AS IS basis without any warranty
*****************************************************************************************
TERMS OF USE     :  This module is copyrighted. Please keep the Copyright notice intact.
*****************************************************************************************/
using System;

namespace BusNY
{
    internal enum UnitSystem { SI = 0, US = 1 }
    
    internal static class GIS
    {
        #region internal: properties (read-only)
        internal static double EarthRadiusKm { get {return _radiusEarthKM;} }
        internal static double EarthRadiusMiles { get { return _radiusEarthMiles; } }
        internal static double m2km { get { return _m2km; } }
        internal static double Deg2rad { get { return _toRad; } }
        #endregion

        #region private: const
        private const double _radiusEarthMiles = 3959;
        private const double _radiusEarthKM = 6371;
        private const double _m2km = 1.60934;
        private const double _toRad = Math.PI / 180;
        #endregion

        #region public Method: Spherical Earth projection
        public static double DistanceSEP(double Lat1,
                                        double Lon1,
                                        double Lat2,
                                        double Lon2,
                                        UnitSystem UnitSys ){
            try
            {
                double _radLat1 = Lat1 * _toRad;
                double _radLat2 = Lat2 * _toRad;
                double _dLat = (_radLat2 - _radLat1);
                double _dLon = (Lon2 - Lon1) * _toRad;

                double _a = (_dLon) * Math.Cos((_radLat1 + _radLat2) / 2);

                // central angle, aka arc segment angular distance
                double _centralAngle = Math.Sqrt(_a * _a + _dLat * _dLat);

                // great-circle (orthodromic) distance on Earth between 2 points
                if (UnitSys == UnitSystem.SI) { return _radiusEarthKM * _centralAngle; }
                else { return _radiusEarthMiles * _centralAngle; }
            }
            catch { throw; }
        }
        #endregion
    }
}

References

  1. The Orthodromic Distance Between Two Geo-points

License

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