Click here to Skip to main content
15,886,362 members
Articles / Hosted Services / Azure

GPS Runner Maps: My First Windows Azure Application

Rate me:
Please Sign up or sign in to vote.
4.90/5 (12 votes)
20 Dec 2009CPOL3 min read 55.2K   3.1K   63  
It is "cloud" Web application to display GPS tracks on Google or Bing maps
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Globalization;
using System.Web.Script.Services;
using System.Web.Services;

namespace PS.GpsRunnerMaps
{

  // To allow this Web Service to be called from script using ASP.NET AJAX,  
  // we need to set the following attribute. 
  [ScriptService]
  [WebService(Namespace = "Panoramio")]
  [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]

  public class PanoramioService : WebService
  {
    [WebMethod]
    public string GetWeatherByLocation(double lat, double lng)
    {
      return Panoramio.GetWeatherByLocation(lat, lng);
    }
  } // end class

  public class Panoramio
  {
    private readonly static string FindNearbyWeatherUrl =
        "http://ws.geonames.org/findNearByWeatherJSON?lat={0}&lng={1}";



    public static string GetWeatherByLocation(double lat, double lng)
    {
      string formattedUri = String.Format(CultureInfo.InvariantCulture,
                            FindNearbyWeatherUrl, lat, lng);


      HttpWebRequest webRequest = GetWebRequest(formattedUri);
      HttpWebResponse response = (HttpWebResponse)webRequest.GetResponse();
      string jsonResponse = string.Empty;
      using (StreamReader sr = new StreamReader(response.GetResponseStream()))
      {
        jsonResponse = sr.ReadToEnd();
      }

      return jsonResponse;
    }

    private static HttpWebRequest GetWebRequest(string formattedUri)
    {
      // Create the request’s URI.
      Uri serviceUri = new Uri(formattedUri, UriKind.Absolute);
      // Return the HttpWebRequest.
      return (HttpWebRequest)System.Net.WebRequest.Create(serviceUri);
    }
  } // end class
}

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)


Written By
Web Developer Forthnet
Greece Greece
Software developer and Microsoft Trainer, Athens, Greece (MCT, MCSD.net, MCSE 2003, MCDBA 2000,MCTS, MCITP, MCIPD).

Comments and Discussions