Building a Store Locator ASP.NET Application Using Google Maps API

Published 25 May 10 11:39 AM | Scott Mitchell

The past couple of projects I've been working on have included the use of the Google Maps API and geocoding service in websites for various reasons. I decided to tie together some of the lessons learned, build an ASP.NET store locator demo, and write about it on 4Guys. Last week I published the first article in what I think will be a three-part series: Building a Store Locator ASP.NET Application Using Google Maps (Part 1). Part 1 walks through creating a demo where a user can type in an address and any stores within a (roughly) 15 mile area will be displayed in a grid. The article begins with a look at the database used to power the store locator (namely, a single table that contains one row for every location, with each location storing its store number, address, and, most important, latitude and longitude coordinates) and then turns to using Google's geocoding service to translate a user-entered address into latitude and longitude coordinates. The latitude and longitude coordinates are used to find nearby stores, which are then displayed in a grid.

Part 2 looks at enhancing the search results to include a map with markers indicating the position of each nearby store location. The Google Maps API, along with a bit of client-side script and server-side logic, make this actually pretty straightforward and easy to implement. Here's a screen shot of the improved store locator results.

Part 3, which I plan on publishing next week, looks at how to enhance the map by using information windows to display address information when clicking a marker. Additionally, I'll show how to use custom icons for the markers so that instead of having the same marker for each nearby location the markers will be images numbered 1, 2, 3, and so on, which will correspond to a number assigned to each search result in the grid. The idea here is that by numbering the search results in the grid and the markers on the map visitors will quickly be able to see what marker corresponds to what search result.

This article and demo has been a lot of fun to write and create, and I hope you enjoy reading it, too.

Happy Programming!

Filed under:


# Joshua said on June 10, 2010 04:49 PM:

Ok, I fixed my own problem from my previous post.  Here's how I did it.

FILE: GoogleMapHelpers.js

//Declare global markers array

var allMarkerList = [];


for (var i = 0; i < markers.length; i++) {


//Add marker to global array

allMarkerListIdea = marker



//Function to open infowindow from an outside link

function openInfo(i)

{google.maps.event.trigger(allMarkerListIdea, 'click');}

FILE: ShowStoreLocations.aspx

Inside listview

<a href='javascript:openInfo(<%# Container.DisplayIndex %>);'>[image]</a>

There ya go.  Now users can click on the numbered image in the listview and have the cooresponding infowindow open in the map.

# Scott Mitchell said on July 7, 2010 02:24 PM:

Part 3 of the article series is available online at

# Soeren said on July 8, 2010 05:48 PM:

SELECT StoreNumber, Address, City, Region, CountryCode, PostalCode, Latitude, Longitude, SQRT(POWER(Latitude - @Latitude, 2) + POWER(Longitude - @Longitude, 2)) * 62.1371192 AS DistanceFromAddress FROM Stores WHERE (ABS(Latitude - @Latitude) &lt; 0.25) AND (ABS(Longitude - @Longitude) &lt; 0.25) ORDER BY DistanceFromAddress

What would this look like in LINQ?

# Daniel Leiva said on July 9, 2010 09:04 AM:

Scott did not appear on the map markers in Part 2. It loads the map of the world of no markers in the area. Any ideas?

# David Haupt said on July 26, 2010 07:53 AM:

Any ideas on why I would be getting: "The remote name could not be resolved: ''".

# Kannan said on September 6, 2010 09:20 AM:

Even I'm getting the same error: "The remote name could not be resolved: ''". Any ideas please?

Leave a Comment



My Books

  • Teach Yourself ASP.NET 4 in 24 Hours
  • Teach Yourself ASP.NET 3.5 in 24 Hours
  • Teach Yourself ASP.NET 2.0 in 24 Hours
  • ASP.NET Data Web Controls Kick Start
  • ASP.NET: Tips, Tutorials, and Code
  • Designing Active Server Pages
  • Teach Yourself Active Server Pages 3.0 in 21 Days

I am a Microsoft MVP for ASP.NET.

I am an ASPInsider.