/// <summary>
        /// Make the constructor private becasuse we want the GetInstance be used.
        /// </summary>
        /// <param name="userid">MapPoint userid</param>
        /// <param name="password">MapPoint password</param>
        private MapPointWebServiceHelper(string userid, string password)
        {
            try
            {
                netCreds = new NetworkCredential(userid, password);

                theMapPointFindService             = new FindServiceSoap();
                theMapPointFindService.Credentials = netCreds;
                theMapPointFindService.Timeout     = MAPPOINT_DEFAULT_TIMEOUT;
                if (webProxy != null)
                {
                    theMapPointFindService.Proxy = webProxy;
                }

                theMapPointRouteService             = new RouteServiceSoap();
                theMapPointRouteService.Credentials = netCreds;
                theMapPointRouteService.Timeout     = MAPPOINT_DEFAULT_TIMEOUT;
                if (webProxy != null)
                {
                    theMapPointRouteService.Proxy = webProxy;
                }

                // setup route distances to be in miles
                UserInfoRouteHeader routeHeader = new UserInfoRouteHeader();
                // set distance in miles
                routeHeader.DefaultDistanceUnit = DistanceUnit.Mile;
                theMapPointRouteService.UserInfoRouteHeaderValue = routeHeader;

                theMapPointRenderService             = new RenderServiceSoap();
                theMapPointRenderService.Credentials = netCreds;
                theMapPointRenderService.Timeout     = MAPPOINT_DEFAULT_TIMEOUT;
                if (webProxy != null)
                {
                    theMapPointRenderService.Proxy = webProxy;
                }
            }
            catch (Exception e)
            {
                throw e;                 // app can handle it
            }
        }
Exemplo n.º 2
0
        public static SqlString Geocode(SqlString AddressLine,
                                        SqlString PrimaryCity,
                                        SqlString Subdivision,
                                        SqlString PostalCode,
                                        SqlString CountryRegion,
                                        SqlString UserName,
                                        SqlString Password)
        {
            FindServiceSoap findService = new FindServiceSoap();

            findService.Credentials
                = new NetworkCredential(UserName.ToString(), Password.ToString());

            FindAddressSpecification addressToGeocode
                = new FindAddressSpecification();

            Address address = new Address();

            address.AddressLine   = AddressLine.ToString();
            address.PrimaryCity   = PrimaryCity.ToString();
            address.Subdivision   = Subdivision.ToString();
            address.PostalCode    = PostalCode.ToString();
            address.CountryRegion = CountryRegion.ToString();

            addressToGeocode.InputAddress = address;
            // NOTE: need to use the appropriate MapPoint location (NA for North America)
            addressToGeocode.DataSourceName = "MapPoint.AP";

            FindOptions findOptions = new FindOptions();

            // we only want latitude and longitude
            findOptions.ResultMask = FindResultMask.LatLongFlag;

            FindRange findRange = new FindRange();

            findRange.StartIndex = 0;
            findRange.Count      = 1;

            findOptions.Range = findRange;

            addressToGeocode.Options = findOptions;

            FindResults findResults;

            findResults = findService.FindAddress(addressToGeocode);

            SqlString locatedAddress = new SqlString();

            if (findResults.Results.Length > 0)
            {
                locatedAddress
                    = "POINT("
                      + findResults.Results[0].FoundLocation.LatLong.Longitude
                      + " "
                      + findResults.Results[0].FoundLocation.LatLong.Latitude
                      + ")";
            }
            else
            {
                locatedAddress = "POINT EMPTY";
            }

            return(locatedAddress);
        }
Exemplo n.º 3
0
    /*
    *********************************************************************************************************
    *                                              GetGPSFromAdress()
    *
    * Description : Cette fonction converti une adresse en coordonnées GPS
    *
    * Argument(s) : strOrigAddress  L'adresse de départ 
    * 
    * Note        : Le format du string à passer en argument à la fonction est celui-ci:
    *               "ADRESSE;VILLE;PROVINCE;CODE POSTAL;PAYS"  
    *               ex: strOrigAddress = "1408 RUE DE L'EGLISE;SAINT-LAURENT;QC;H4L2H3;CA";
    *********************************************************************************************************
    */
    public static string[] GetGPSFromAdress(string strOrigAddress)
    {
        FindServiceSoap findService = new FindServiceSoap();
        findService.Credentials = new System.Net.NetworkCredential("124624", "PDALE_projets5");
        FindSpecification findSpec = new FindSpecification();
        FindResults startResults = null;
        FindResults endResults = null;


        //Output the formatted address
        string[] strTemp = new String[5];
        strTemp = strOrigAddress.Split(';');

        Address myOrigAddress = new Address();
        myOrigAddress.AddressLine = strTemp[0];
        myOrigAddress.PrimaryCity = strTemp[1];
        myOrigAddress.Subdivision = strTemp[2];
        myOrigAddress.PostalCode = strTemp[3];
        myOrigAddress.CountryRegion = strTemp[4];

        FindAddressSpecification findOrigAddressSpec = new FindAddressSpecification();
        findOrigAddressSpec.InputAddress = myOrigAddress;
        findOrigAddressSpec.DataSourceName = "MapPoint.NA";

        //Retrieve the values of startResults
        try
        {
            startResults = findService.FindAddress(findOrigAddressSpec);
        }
        catch (Exception e2)  //The request failed with HTTP status 401: Unauthorized.
        {
            Console.WriteLine("Problem connecting with service");
        }

        // Make sure findResults isn't null
        if (startResults == null)
        {
            Console.WriteLine("Originating Address not found.");
        }
        else
        {
            // If no results were found, display error and return
            if (startResults.NumberFound == 0)
            {
                Console.WriteLine("Originating Address not found.");
            }
        }

        string[] strLongLat = new string[2];
        strLongLat[0] = startResults.Results[0].FoundLocation.LatLong.Longitude.ToString();
        strLongLat[1] = startResults.Results[0].FoundLocation.LatLong.Latitude.ToString();

        return strLongLat;
    }
        public static SqlString geocode(
            SqlString AddressLine,
            SqlString PrimaryCity,
            SqlString Subdivision,
            SqlString PostalCode,
            SqlString CountryRegion)
        {
            // Initialize the MapPoint Find service
            FindServiceSoap findService = new FindServiceSoap();

            // Provide the logon credentials
            string UserName = "******";
            string Password = "******";

            findService.Credentials = new NetworkCredential(UserName, Password);

            // FindAddressSpecification contains the details passed to the Find service
            FindAddressSpecification findAddressSpec = new FindAddressSpecification();
            // Build a new address object from the parameters provided to the function
            Address address = new Address();

            address.AddressLine   = AddressLine.ToString();
            address.PrimaryCity   = PrimaryCity.ToString();
            address.Subdivision   = Subdivision.ToString();
            address.PostalCode    = PostalCode.ToString();
            address.CountryRegion = CountryRegion.ToString();
            // Add the address to search for to the specification
            findAddressSpec.InputAddress = address;
            // Specify the data source in which to search for the address
            findAddressSpec.DataSourceName = "MapPoint.NA";

            // Create the options to limit the result set
            FindOptions findOptions = new FindOptions();

            // Filter the results to only show LatLong information
            findOptions.ResultMask = FindResultMask.LatLongFlag;
            // Only return the first matching result
            FindRange findRange = new FindRange();

            findRange.StartIndex = 0; findRange.Count = 1;
            findOptions.Range    = findRange;
            // Apply the options to the specification
            findAddressSpec.Options = findOptions;

            // Call the MapPoint Web Service and retrieve the results
            FindResults findResults; findResults = findService.FindAddress(findAddressSpec);

            // Create the WKT representation of the geocoded result
            SqlString WKT = new SqlString();

            if (findResults.Results.Length > 0)
            {
                WKT = "POINT(" +
                      findResults.Results[0].FoundLocation.LatLong.Longitude + " " +
                      findResults.Results[0].FoundLocation.LatLong.Latitude + ")";
            }
            else
            {
                WKT = "POINT EMPTY";
            }

            // Return the result to SQL Server
            return(WKT);
        }
Exemplo n.º 5
0
        private static GeoPoint GetGeoPositionMicrosoft(string address, string plz, string city, string region, string country)
        {
            GeoPoint        geoPoint    = null;
            FindServiceSoap findService = new FindServiceSoap();

            string myUserID   = Properties.Settings.Default.MPUser;
            string myPassword = Properties.Settings.Default.MPPass;

            NetworkCredential myCredentials = new NetworkCredential(myUserID, myPassword);

            findService.Credentials     = myCredentials;
            findService.PreAuthenticate = true;
            string addressLine    = (address != null) ? address.Trim() : string.Empty;
            string zipCode        = (plz != null) ? plz.Trim() : string.Empty;
            string stadt          = (city != null) ? city.Trim() : string.Empty;
            string kanton         = (region != null) ? region.Trim() : string.Empty;
            string land           = (country != null) ? country.Trim() : string.Empty;
            string dataSourceName = "MapPoint.EU";

            if (land.Length == 0)
            {
                land = "switzerland";
            }
            if (kanton.Length == 0)
            {
                kanton = stadt;
            }

            FindOptions myFindOptions = new FindOptions();

            myFindOptions.ThresholdScore   = 0.5;
            myFindOptions.Range            = new FindRange();
            myFindOptions.Range.StartIndex = 0;
            myFindOptions.Range.Count      = 1;
            //Try find exact address

            Address myAddress = new Address();

            myAddress.AddressLine   = addressLine;
            myAddress.PrimaryCity   = stadt;
            myAddress.SecondaryCity = string.Empty;
            myAddress.Subdivision   = kanton;
            myAddress.PostalCode    = zipCode;
            myAddress.CountryRegion = land;

            FindAddressSpecification findAddressSpec = new FindAddressSpecification();

            findAddressSpec.InputAddress = myAddress;
            findAddressSpec.Options      = myFindOptions;

            FindSpecification findSpec   = new FindSpecification();
            string            inputPlace = string.Format("{0},{1},{2}", city, kanton, land);

            inputPlace          = inputPlace.Replace(",,", "").TrimStart(',');
            findSpec.InputPlace = inputPlace;

            FindResults myFindResults = null;

            FindResult[] myResults = null;
            try
            {
                findAddressSpec.DataSourceName = dataSourceName;
                myFindResults = findService.FindAddress(findAddressSpec);
            }
            catch
            {
            }
            if (myFindResults != null && myFindResults.Results != null && myFindResults.Results.Count() > 0)
            {
                myResults = myFindResults.Results;
                if (myResults.Count() > 0)
                {
                    geoPoint = FillGeoPoint(myResults[0]);
                }
            }
            else
            {
                //Try finding by Location

                try
                {
                    findSpec.DataSourceName = dataSourceName;
                    myFindResults           = findService.Find(findSpec);
                }
                catch
                {
                }
                if (myFindResults != null && myFindResults.Results != null && myFindResults.Results.Count() > 0)
                {
                    myResults = myFindResults.Results;
                    geoPoint  = FillGeoPoint(myResults[0]);
                }
            }
            if (geoPoint == null)
            {
                //still nothing
                //try it again with new datasource
                myFindResults  = null;
                myResults      = null;
                dataSourceName = "MapPoint.NA";
                try
                {
                    findAddressSpec.DataSourceName = dataSourceName;
                    myFindResults = findService.FindAddress(findAddressSpec);
                }
                catch
                {
                }
                if (myFindResults != null && myFindResults.Results != null && myFindResults.Results.Count() > 0)
                {
                    myResults = myFindResults.Results;
                    if (myResults.Count() > 0)
                    {
                    }
                }
                else
                {
                    //Try finding by Location

                    try
                    {
                        findSpec.DataSourceName = dataSourceName;
                        myFindResults           = findService.Find(findSpec);
                    }
                    catch
                    {
                    }
                    if (myFindResults != null && myFindResults.Results != null && myFindResults.Results.Count() > 0)
                    {
                        myResults = myFindResults.Results;
                        geoPoint  = FillGeoPoint(myResults[0]);
                    }
                }
            }
            return(geoPoint);
        }