Friday, September 10, 2010

ve: VEWS 5 finally …

Posted by david on 1. February 2009 11:18

 now to pull the geoservice stuff out of the page code behind & into it's own component or class ....

  • Add new project, class library, VEWS, to solution
  • ah,maybe I see what went wrong the last go round. The class library has it’s own reference section – where I can Add Reference or Add Service Reference 
  • Back up again – I still can’t see how to get both the staging service ( a web ref ) and the services ref ( that weird svcutil generated file )  … gonna just build the token & geocode into a class in the App_Code folder.  Per the previous post, a tightly coupled component.
    • Add class, VEWSGeo.cs
    • give it a string clientIP because we need to bring in the client IP for the token service … so the page will set that
      • private string clientIP
      • do the Property code
      • 																					public string ClientIP																		
        			
        																					{																		
        			
        																					    get																		
        			
        																					    { return clientIP; }																		
        			
        																					    set																		
        			
        																					    { clientIP = value; }																		
        			
        																					}																		
        			
    • need a method to get the VEWS token
        																					private string GetToken(string clientIP)																		
        			
        																					        {																		
        			
        																					            // Set Virtual Earth Platform Developer Account credentials to access the Token Service																		
        			
        																					            CommonService commonService = new CommonService();																		
        			
        																					            commonService.Credentials = new System.Net.NetworkCredential("your ve id", "your ve password");																		
        			
        																					 																		
        			
        																					            // Set the token specification properties																		
        			
        																					            TokenSpecification tokenSpec = new TokenSpecification();																		
        			
        																					            tokenSpec.ClientIPAddress = clientIP;																		
        			
        																					            tokenSpec.TokenValidityDurationMinutes = 60;																		
        			
        																					 																		
        			
        																					            string token = "";																		
        			
        																					 																		
        			
        																					            // Get a token																		
        			
        																					            try																		
        			
        																					            {																		
        			
        																					                token = commonService.GetClientToken(tokenSpec);																		
        			
        																					            }																		
        			
        																					            catch (Exception ex)																		
        			
        																					            {																		
        			
        																					                throw ex;																		
        			
        																					            }																		
        			
        																					            return token;																		
        			
        																					        }																		
        			
    • & then a method to get geocode an address & return a latlong
    • 														public LatLong GetLatLong(string InputAddress)												
      		
      														{												
      		
      														    LatLong ResultLatLong = new LatLong();												
      		
      														 												
      		
      														    string token = GetToken(clientIP);												
      		
      														    dev.virtualearth.net.webservices.v1.geocode.GeocodeRequest geoRequest = new dev.virtualearth.net.webservices.v1.geocode.GeocodeRequest();												
      		
      														    geoRequest.Credentials = new dev.virtualearth.net.webservices.v1.common.Credentials();												
      		
      														    geoRequest.Credentials.Token = GetToken(clientIP);												
      		
      														    geoRequest.Query = InputAddress;												
      		
      														 												
      		
      														    dev.virtualearth.net.webservices.v1.geocode.GeocodeOptions myOptions = new dev.virtualearth.net.webservices.v1.geocode.GeocodeOptions();												
      		
      														    myOptions.Count = 1;												
      		
      														 												
      		
      														    GeocodeServiceClient myServiceClient = new GeocodeServiceClient();												
      		
      														 												
      		
      														    dev.virtualearth.net.webservices.v1.geocode.GeocodeResponse myGeocodeResponse = myServiceClient.Geocode(geoRequest);												
      		
      														 												
      		
      														    ResultLatLong.Latitude = myGeocodeResponse.Results[0].Locations[0].Latitude;												
      		
      														    ResultLatLong.Longitude = myGeocodeResponse.Results[0].Locations[0].Longitude;												
      		
      														 												
      		
      														    return ResultLatLong;												
      		
      														 												
      		
      														}												
      		
    • & the click code looks like this:
    • 														protected void btnGeocode_Click(object sender, EventArgs e)												
      		
      														{												
      		
      														    string addressInput = inputtextbox.Text; 												
      		
      														    LatLong resultLatLong = new LatLong();												
      		
      														 												
      		
      														    VEWSGeo myVEWSGeo = new VEWSGeo();												
      		
      														    myVEWSGeo.ClientIP = Page.Request.UserHostAddress;												
      		
      														 												
      		
      														    resultLatLong = myVEWSGeo.GetLatLong(addressInput);												
      		
      														 												
      		
      														    litLatitude.Text = resultLatLong.Latitude.ToString();												
      		
      														    litLongitude.Text = resultLatLong.Longitude.ToString();												
      		
      														 												
      		
      														}												
      		

& it works ( ! ) 2009_02_01

a few times, on first load, I’ve entered in just a zip code & it is returning null.  but then works next time. not sure bout that yet.

Changing the mouse icon during an update (javascript)

another styling the progress instruction

here’s my css for the current page … not perfect but at least it’s floating on top of everything rather than busting inline

#UpdateProgress1 {
 
   left:5%;
   position:fixed;
 }
 
#UpdateProgress1 img {
   vertical-align:middle;
   margin:2px;
 }
<ProgressTemplate>
              
    <img src="../../Images/earth03.gif" style="height: 60px; width: 60px" />&nbsp; 
            
<ProgressTemplate>

Animated GIF Images - Globes

 

 

 

 

 

2009_02_01

good! finally! i deserve a beer!

Comments

Add comment


 

biuquote
Loading