Simplest Scenario. Put list of cities in Indonesia in string collection and display it in dropdown list.
private string[] Cities = new string[]
{
"Banda Aceh , ID",
"Medan , ID",
"Pakanbaru , ID",
"Batam , ID",
"Padang , ID",
"Jambi , ID",
"Palembang , ID",
"Pangkal Pinang , ID",
"Bengkulu , ID",
"Bandar Lampung , ID",
"Pontianak , ID",
"Samarinda , ID",
"Palangkaraya , ID",
"Banjarmasin , ID",
"Menado , ID",
"Gorontalo , ID",
"Palu , ID",
"Kendari , ID",
"Makassar , ID",
"Majene , ID",
"Ternate , ID",
"Ambon , ID",
"Jayapura , ID",
"Sorong , ID",
"Biak , ID",
"Manokwari , ID",
"Merauke , ID",
"Kupang , ID",
"Sumbawa Besar , ID",
"Mataram , ID",
"Denpasar , ID",
"Jakarta , ID",
"Serang , ID",
"Bandung , ID",
"Semarang , ID",
"Yogyakarta , ID",
"Surabaya , ID"
};
Then you can use the Animaonline DLL (Windows Mobile version is available) to query Google Maps API. Very easy, just add reference to the downloaded animaonline DLL in your project then put the following codes snippet for Show Data event handler method:
Animaonline.GeoServices.GeoCode.ApiKey =
@"ABQIAAAAYLumHTv11x4C0SeD1dju_hR1L4k4lZLEfduCoVr7aBMzMPP6bRT1dqi20tlAWBkMGPUkXEc1qTd8bQ";
Animaonline.WeatherAPI.WeatherData wD = new WeatherData(LanguageCode.en_US, cityNameSelected, true, true);
Once you get your wD object created, you can use its properties to display weather condition including its 3 days forecast.
this.lblCityVal.Text = wD.city;
this.lblDay1Val.Text = wD.day_of_weekDAY2 + " " + wD.conditionDAY2;
this.lblDay2Val.Text = wD.day_of_weekDAY3 + " " + wD.conditionDAY3;
this.lblHumidityVal.Text = wD.humidity;
this.lblTempVal.Text = wD.temp_c.ToString();
this.lblTimeVal.Text = wD.current_date_time.ToString();
this.lblTodayVal.Text = wD.conditionTODAY;
this.lblTomorrowVal.Text = wD.conditionTOMORROW;
this.lblWindVal.Text = wD.wind_condition;
You can get Google Maps API key from this link and the result will be like this:
If you have nice icons, WeatherData (wD) object also can help you to locate the image icons. Weather condition is common for all Weather services, for example cloudy, partly_cloudy, etc condition from Yahoo Weather API. Also, if you dont want to use Yahoo Weather API, you can get many free weather icons in Internet or make your own Indonesian version.
What else? Hmmm the map. Look on the code below:
Animaonline.GeoServices.GeoCode.ApiKey =
@"ABQIAAAAYLumHTv11x4C0SeD1dju_hR1L4k4lZLEfduCoVr7aBMzMPP6bRT1dqi20tlAWBkMGPUkXEc1qTd8bQ";
Animaonline.WeatherAPI.WeatherData wD = new WeatherData(LanguageCode.en_US, cityNameSelected, true, true);
string weatherString = string.Format("City:{0} Condition:{1} Temperature:{2}°F {3}°C", wD.city, wD.condition, wD.temp_f, wD.temp_c);
Animaonline.Maps.GoogleMapGenerator.Map myMap = new Animaonline.Maps.GoogleMapGenerator.Map(wD.latitude_e6, wD.longitude_e6, weatherString, 640, 480, 11);
Once you have your myMap object, you can save an HTML file for example (Makassar.html) using this following code:
myMap.SaveMap(“Makassar.html”);
The generated HTML will give you the Google Map HTML Script viewer:
If you want to combine your your viewer with WebBrowser control, let say, your control name is myWebBrowser, then you can use the other method to bind the generated HTML to your WebBrowser control”
FileStream source = new FileStream("Makassar.html", FileMode.Open, FileAccess.Read);
myWebBrowser.DocumentStream = source;
myWebBrowser.Refresh();
If you prefer NOT to generate HTML, but directly bind the mapHTML stream to your WebBrowser control, you can do handler codes like below:
Animaonline.GeoServices.GeoCode.ApiKey =
@"ABQIAAAAYLumHTv11x4C0SeD1dju_hR1L4k4lZLEfduCoVr7aBMzMPP6bRT1dqi20tlAWBkMGPUkXEc1qTd8bQ";
Animaonline.WeatherAPI.WeatherData wD = new WeatherData(LanguageCode.en_US, cityNameSelected, true, true);
string weatherString = string.Format("City:{0} Condition:{1} Temperature:{2}°F {3}°C", wD.city, wD.condition, wD.temp_f, wD.temp_c);
Animaonline.Maps.GoogleMapGenerator.Map myMap = new Animaonline.Maps.GoogleMapGenerator.Map(wD.latitude_e6, wD.longitude_e6, weatherString, 640, 480, 11);
myWebBrowser.DocumentText = myMap.MapHtml;
myWebBrowser.Refresh();
Other API that you may use is Yahoo Weather API. I am thinking to make simple IE8 Web Slice ready scripts using Yahoo Feed. Let see if I have my insomnia time this weekend, so I can take REST with weather, kidding…. :) Remembering weather, we have a lot of urgency in Indonesia to start doing something about it. I believe many developers here can do something, for example:
- Create Indonesian weather services as wrapper from other weather APIs
- Create cool reusable weather viewer using Silverlight, WPF, Compact Framework, Popfly, IE8 etc.
Have nice insomnia weekend and hope this helps!
Cheers – RAM