MapPoint Forums

MapForums

Community of VE/MapPoint Users and Developers




Virtual Earth and Microsoft Commerce Server

This is a discussion on Virtual Earth and Microsoft Commerce Server within the Virtual Earth Blogs forums, part of the Blogs category; If you've visited us at the Microsoft booth at the Shop.org conference , you may have seen the Microsoft Virtual ...


Go Back   MapPoint Forums > Blogs > Virtual Earth Blogs

Register Blogs FAQ Members List Calendar Search Today's Posts Mark Forums Read



Click here to register

Reply

 

LinkBack (2) Thread Tools Display Modes
  2 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 09-17-2008
Senior Member
Blue Belt
 
Join Date: Sep 2007
Posts: 202
Virtual Earth and Microsoft Commerce Server

If you've visited us at the Microsoft booth at the Shop.org conference, you may have seen the Microsoft Virtual Earth demonstration application illustrating Microsoft Commerce Server 2007 and Virtual Earth working together. The concept for the application is based on inventory data in Commerce Server being used to help end users find the nearest location that carries the item you're searching for - an advanced store locator and inventory search scenario.

image

The demonstration application is posted online branded as "Soundshift Multi-Channel Retailing." To use the application, you'll want to go to the "stores" tab and enter '90210' in the address box. You'll be presented with the results around the Los Angeles area inclusive of custom pushpins, custom EROs and how 'bout that custom navigation bar? Nice. In the "Directions" tab you can get directions, find gas stations along the route, find coffee shops along the route, show traffic, print the directions, send to email, and send to mobile. A pretty robust application, eh?

So, to most of you this is just a plain old store location - whoopie! The important piece is what happens behind the scenes. The folks at Cactus Commerce built the implementation and wrote a white paper describing how to leverage both Windows Live ID and Virtual Earth within Commerce Server. The document provides architecture and code details of how this can be done using the Commerce Server's extensibility model. From the document, you'll find the architecture and code level instructions for integrating the following features into Commerce Server - geocoding a user's address, finding the nearest stores, retrieving items in the basket, getting inventory status, and adding store and inventory information to the Virtual Earth map.

image

Geocode User’s Address

The first step in locating nearby stores is to geocode the user’s address to latitude and longitude coordinates. You can use the Find method from the Virtual Earth’s Map Control to resolve the address. For simplicity, we will assume only one result is returned:

function findAddress(address, map)

{

// Call VEMap.Find() to geocode address

map.Find(null, address, null, null, null, null, false, false, true, true,

findAddressCallBack);

}

// Call back function for VEMap.Find()

function findAddressCallBack(thelayer, resultsArray, places, hasMore, veErrorMessage)

{

if(places != null && places.length >0)

{

var latitude = places[0].LatLong.Latitude;

var longitude = places[0].LatLong.Longitude;

}

}

Retrieve Nearby Stores

Once we have the user’s geocode, we can implement the logic to find nearby stores within a given radius:

private void GetNearbyStores(ProfileManagementContext profileCtx, double latitude,

double longitude, double radius, List stores)

{

// Retrieve store list

DataSet dsEntities = profileCtx.GetSearchableEntities();

SearchClauseFactory scf = profileCtx.GetSearchClauseFactory(dsEntities, "Store");

SearchClause searchClause = scf.CreateClause();

Microsoft.CommerceServer.SearchOptions searchOptions =

new Microsoft.CommerceServer.SearchOptions();

searchOptions.PropertiesToReturn =

"u_store_id,u_name,u_address,u_virtual_catalog, latitud,longitude";

DataSet ds = profileCtx.ExecuteSearch("StoreObject", searchClause, searchOptions);

// Find nearby stores

if (ds != null && ds.Tables.Count > 0)

{

foreach (DataRow r in ds.Tables[0].Rows)

{

double storeLat = double.Parse(r["latitud"].ToString());

double storeLon = double.Parse(r["longitude"].ToString());

// CalculateDistance() implements the Mercator's Projection

// to determine the distance between 2 points

if (CalculateDistance(lat, lon, storeLat, storeLon) < radius)

{

// Store is within the specified radius

Store store = new Store();

store.ID = r["u_store_id"].ToString();

store.Name = r["u_name"].ToString();

store.Address = r["u_address"].ToString();

store.VirtualCatalog = r["u_virtual_catalog"].ToString();

store.Latitude = storeLat;

store.Longitude = storeLon;

stores.Add(store);

}

}

}

}

Retrieve Basket Items

In order to build up the store stock status return data set, we need to retrieve the list of products from the user’s basket:

// Get list of product and quantity from user's basket

private void GetBasketItems(GUID userID, string basketName, List basketItems)

{

// Get the user's shopping cart

Basket basket = CommerceContext.Current.OrderSystem.GetBasket(user ID, basketName);

foreach (OrderForm orderForm in basket.OrderForms)

{

foreach (LineItem lineItem in orderForm.LineItems)

{

// Store basket item

BasketItem basketItem = new BasketItem();

basketItem.ProductID = lineItem.ProductId.ToString();

basketItem.ProductName = lineItem.DisplayName.ToString();

basketItem.Quantity = lineItem.Quantity;

basketItems.Add(basketItem);

}

}

}

Retrieve Store Inventory Status

We are now ready to retrieve on hand quantity for each store items:

private void GetStoreInventoryStatus(InventoryContext inventoryCtx, List stores,

List basketItems)

{

foreach (Store store in stores)

{

// Get the inventory catalog for the current store

InventoryCatalog inventoryCatalog =

inventoryCtx.GetAssociatedInventoryCatalog(store.V irtualCatalog);

foreach (BasketItem basketItem in basketItems)

{

// Get Inventory Sku

InventorySku inventorySku =

inventoryCatalog.GetSku(store.VirtualCatalog,

basketItem.ProductID);

// Add inventory status to store

ItemStatus itemStatus = new ItemStatus();

itemStatus.ProductID = basketItem.ProductID;

itemStatus.StockStatus = (inventorySku.Quantity - basketItem.Quantity) >= 0 ?

"In Stock" : "Not Available";

store.ItemStatusList.Add(itemStatus);

}

}

}

Add Stores and Inventory Status to Virtual Earth Map

Now that we have all the Store inventory data, we will be adding pushpins and popup descriptions to the Virtual Earth Map via client side scripting:

· Create a new instance of the map control and add a shape layer:

map = new VEMap('myMap');

map.LoadMap();

layer = new VEShapeLayer();

map.AddShapeLayer(layer);

layer.Hide();

· Create pushpin shape and add the shape layer

// jsStoreStockData contains store inventory status retrived from

// previous steps

for (var i=0; i < jsStoreStockData.stores.length; i++)

{

// Create shape (pushpin)

var latLong = new VELatLong(jsStoreStockData.stores[i].Latitude,

jsStoreStockData.stores[i].Longitude) ;

var shape = new VEShape(VEShapeType.Pushpin, latLong);

shape.SetTitle('

'+jsStoreStockData.stores[i].Name+'

');

shape.SetCustomIcon("store

src='images/logo_vista.png'/>");

// Generate basket item stock status as shape description

var desc = '

'+jsStoreStockData.stores[i].Address+'' ;

desc += '

'

for (var j = 0; k < jsStoreStockData.stores[i].ItemStatusList.length; j++)

{

desc += '

';

}

desc += '

ProductStock Status
'+jsStoreStockData.stores[i].ItemStatusList[j].ProductName

+ '

';

desc += jsStoreStockData.stores[i].ItemStatusList[j].StockStatus

+ '

';

shape.SetDescription(desc);

// Add pushpin to ShapeLayer

layer.AddShape(shape);

// Center map and set zoom level

SetCenterAndZoom();

// Show the ShapeLayer

layer.Show();

}

If you have Microsoft Commerce Server 2007, your integration with Microsoft Virtual Earth just got a heck of a lot easier. The flexibility of the Virtual Earth platform allows for data visualization from almost any data repository whether it be Microsoft products like Commerce Server, CRM or SQL Server or non-Microsoft data sources such as Siebel, Oracle or MySQL. The proliferation of data visualization using mapping across the web and software products just keeps getting better, doesn't it?

CP



Click here to view the article.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply


LinkBacks (?)
LinkBack to this Thread: http://www.mapforums.com/virtual-earth-microsoft-commerce-server-8553.html

Posted By For Type Date
Geotags.org: Reverse Geocoding - Part II This thread Refback 2 Weeks Ago 12:02 PM
Reverse Geocoding, Pt. III - MapPoint Articles - MP2K Magazine This thread Refback 09-19-2008 12:45 PM

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Announcing the Microsoft Virtual Earth ASP .Net Server Control VirtualEarth MSDN Blog Virtual Earth Blogs 0 07-28-2008 05:21 PM
Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (4/6) Johannes Kebeck's Blog Virtual Earth Blogs 0 03-03-2008 01:51 PM
Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (2/6) Johannes Kebeck's Blog Virtual Earth Blogs 0 03-02-2008 04:52 PM
Virtual Earth & SQL Server 2008 - Part 4: Integrating SQL Server 2008 and Virtual Earth (1/6) Johannes Kebeck's Blog Virtual Earth Blogs 0 03-02-2008 04:52 PM
MapDotNet Server 6.5 Supports SQL Server 2008 and New Virtual Earth Features VE For Government Virtual Earth Blogs 0 11-12-2007 06:42 PM


All times are GMT -5. The time now is 01:52 AM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0
MP2K Magazine
Visitor Map


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55