domenica 25 novembre 2007

An ASP.NET web control wrapping Google Maps API

I'm developing the new version of my real estate web site (http://www.vendercasa.it/) and I would to enrich it with the possibility of browsing the database trough a map, so I decided of interfacing my site with Google Maps; I think the best way to obtain it is to make a web control wrapping a sub-group of Google Maps APIs so I realised a web control, CalSoft.GoogleMaps, that offers methods, properties and events (at the end of the post you can find a reference) useful for interfacing to the Google Maps APIs.


How to use the control in an "ASP.NET Ajax-Enabled Web Site Project":
(note: the control works only in an Ajax project inside an update panel)

1 - Insert as first line of the HTML code the DOCTYPE tag: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN""http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

2 - Insert in the <HEAD> of the HTML code: <script src="http://maps.google.com/maps?file=api&amp;v=2&amp;key=GOOGLE_MAPS_KEY" type="text/javascript"></script> where GOOGLE_MAPS_KEY depends on the URL of your site and you can get it here.

3 - Copy gmap.js in your web site space and insert in the <HEAD> of the HTML code: <script src="./gmaps.js" type="text/javascript"></script> where "gmaps.js" is the file with the javascript client library needed by the control

4 - In the body tag insert onload="GLoad()" onunload="GUnload()"

5 - Insert in your aspx page a ScriptManager and an UpdatePanel. Put outside the UpdatePanel a DIV control and fill it Id property (for example 'MYMAP') and set the dimensions of the control

6 - Add the CalSoft.GoogleMaps control to the toolbox (right click over the toolbox, 'choose items...' and browse the CalSoft DLL), insert a GoogleMaps control in the UpdatePanel, fill the Control property with the Id of the control where you want the map would appear (in previous example "MYMAP"). Set the other properties according to your needs.

Problems/To do:

PanTo doesn't work right
Setting "navigation map controls" properties doesn't work in runtime mode
Test multiple controls in a single page
Impossible to change the 'Control' property at runtime
Implement StringBuilder where possible and useful

Methods, properties and events reference

Methods:

SetCenter(Single sLat, Single sLng, int iZoom)

Set the centre of the map and the zoom factor.

PanTo(Single sLat, Single sLng, int iMillisec)

Pan the map to the specified position in the specified time (milliseconds).(at the moment doesn't work right)

Properties:

bool ZoomChanged
bool MapTypeChanged
bool CoordinatesChanged


These 3 read-only properties warn over a value change.
(respectively zoom, map type and coordinates)

bool GLargeMapControl
bool GSmallMapControl
bool GSmallZoomControl
bool GScaleControl
bool GMapTypeControl
bool GOverviewMapControl


They activate the visualization of the standard navigation controls on the map.
They are valid only at design time, changing them during runtime is useless.

int Zoom

Zoom level.

Single Latitude

Latitude of the centre of the map.

Single Longitude

Longitude of the centre of the map.

string Control

Id of the control (usually a DIV) where the map is displayed.

GMMapType MapType

Map type, the value is an enum:
enum GMMapType { Normal, Satellite, Hybrid, Default }

Single NELatitude
Single NELongitude
Single SWLatitude
Single SWLongitude


Latitudes and longitudes of the north-east and south-west corner of the map. They are read-only.

Events:

OnGMClick(object sender, Single lat, Single lng)

Fired every time the user click on the map.
Lat e lng are the coordinates (latitude and longitude) of the clicked point.

OnGMMove(object sender, string arg)

Fired when the map change (in position, appearance or zoom).
The properties reflect the changes of the map.(The 'arg' argument at the moment isn't implemented and give back only the string 'move').

You can download the control (with all the needed files - source, compiled dll and js library) by clicking here or test it here.

martedì 20 novembre 2007

Visual Studio 2008 Express Released

Last Monday Microsoft released Visual Studio 2008 Express edition.
You can download them here.

Enjoy!

sabato 3 novembre 2007

GMGeodecoder: a class findig places and based on Google Maps

In the last post I proposed a simple web custom control based on the Microsoft Virtual Earth APIs, now a similar class (only places, not business) based on the Google Maps HTTP Geodecoding Service (so it's totally server side, no Ajax, no Javascript).

The class CalSoft.GMGeodecoder has only the constructor and a public method:

public GMGeodecoder(string sGMKey)

This is the constructor with only one parameter: the google maps API key. I'm not sure it is required, but, of course, according to the service description on the manual you must provide it (if you need a google maps API key for your site you can obtain it free here).

public GMPlace GetPlace(string sPlace)

Method that performs a search for the location specified on sPlace and returns a GMPlace structures.

public struct CalSoft.GMPlace

Single Latitude and Longitude
obviously the latitude and longitude of the result place

int Accuracy

an integer representing the accuracy of the result according to that table

int StatusCode
status code of the HTTP request

string Result
the full string returned from the HTTP request

You can download the class by clicking here or test it here.

Good work!

sabato 18 agosto 2007

LocationFinder: a web control findig places

Today a simple web custom control based on the Microsoft Virtual Earth APIs and that can search for places and/or business simply passing what and/or where, similarly to Live Local Search.

The control hasn't any property, but only a method and an event:

void Find(string what, string where, int start, int length)

Method that performs a what (business) search and/or a where (location) search (at least one of these two parameters is required)., for the answer you must wait for the event.

Parameters:
what: the business name, category, or other item searched for(es. "pizza")
where: the address or place name of the area searched for (es. "New York")
start: the beginning index of the results returned
length: the number of results to be returned (max. 20)

void LocationFinder_Found(object sender, VEFindResult[] results, VEPlace[] places, bool hasmore)

Event that returns a list of results and a list of places.

Parameters:
results: array of VEFindResult (list of results)
places: array of VEPlace (list of ambiguous places)
hasmore: true if there are others results (at the moment doesn't work!)

There are also two structures:

CalSoft.VEFindResult

Name
Description
Phone
IsSponsored
Latitude
Longitude

CalSoft.VEPlace

Name
Latitude
Longitude

(the function of each member is intuitive)

You can download the control by clicking here or test it here.
The zip contains the DLL (put it in the bin directory and add the control to the toolbox of Visual Studio) and the source (FadingImage.cs).
How to use the DLL in your WEB projects:
1 - put the DLL fille in the Bin directory of the site;
2 - if you want to add the control to Visual Studio toolbox, right-click on it, click on "Choose Items ..." and browse the project to add the DLL.
Note: if you want to modify the source remeber to add the right references (System.Web, System.Web.Extension, System.Drawing)
That's all.

sabato 4 agosto 2007

FadingImage: a web custom control fading between images

(note: this is my first post in English: I'm learning English, sorry for my mistakes and I will appreciate your kind corrections)

For an ASP.NET project I needed to fade between images, so I decided to write a web custom control: FadingImage.
Usage is easy: changing ImageUrl property the control fades between the previous image and the new one.
It derives from System.Web.UI.WebControls.Image and implements IPostBackEventHandler, I added one property and two events.

Increments
% increment of opacity every 50 milliseconds (for example setting this property to 5 makes images shading in one second). If you don't want fading set this property to 0.

onEndFading(object sender)
occurs each time a fading ends.

onClick(object sender, int t, int x, int y)
occurs for every mouse click over the control, t represent the mousekey (1 = left, 2 = right), x and y the coordinates relative to the control.

Compatibility:
I tested the control with IE7, Firefox 2 and 1.5, Opera 9.21, other visitors advise me that it works with IE6, but I want to compile a complete compatibility list:

Could you help me? Have a look at the image below:

What do you see (Uluru, Sydney skyline or both)? Which is your browser/version? Let me know! Thanks.

You can download the control by clicking here or test it here.
The zip contains the DLL (put it in the bin directory and add the control to the toolbox of Visaul Studio), the source (FadingImage.cs) and the javascript source (not needed by the program because the js code is integrated in the C# code, but I included it for an easier reading).

Note: don't forget to insert the DOCTYPE tag:



How to use the DLL in your WEB projects:

1 - put the DLL fille in the Bin directory of the site;

2 - if you want to add the control to Visual Studio toolbox, right-click on it, click on "Choose Items ..." and browse the project to add the DLL.

Note: if you want to modify the source remeber to add the right references (System.Web, System.Web.Extension, System.Drawing)

Good luck and let me know!