Archive

Archive for June, 2013

Markers on map javascript asp.net c#

June 27, 2013 Leave a comment

Sometimes we gets trouble to mix Javascript and C#.
Here is my asp.net source to display dynamic markers on google map.

http://sdrv.ms/11LvXye

See live here

http://sicsglobal.co.in/mytestproject/themarker/

I called an aspx page to get some places as C# List, and convert the list to Javascript array from the ajax result.
So we can show markers on map using the normal google api functions.

🙂

Advertisements

Deserialize google places json api using JSON.NET C#

June 23, 2013 1 comment

https://maps.googleapis.com/maps/api/place/search/json?location=8.487495,76.948623&radius=50000&sensor=false&key=Your_key&types=bank

The above link will list all banks near trivandrum in json format (around 50km).

The format is

{
“debug_info” : [],
“html_attributions” : [
“Listings by \u003ca href=\”http://www.indiacom.com/\”\u003eIndiacom Yellow Pages\u003c/a\u003e”
],
“next_page_token” : “ClRNAAAAiET0Jb-GWSPRrClKlXoDqUzA70eEBaa2oKXpN0uBnZ0rVeGkmia0x8IT78UKkXnJZ9IKDhXRsydMw-20Qu1vFf0U5WHKd_Vyt6OwA6etDC8SENOghFC6xxe63lx7VL7i5O4aFGrN8gtl_GaPmBQlqcQGYUdnZoao”,
“results” : [
{
“geometry” : {
“location” : {
“lat” : 8.5280190,
“lng” : 76.9387870
}
},
“icon” : “http://maps.gstatic.com/mapfiles/place_api/icons/generic_business-71.png”,
“id” : “03d8927f980ecbe599326209ee5018ebbf1d54e6”,
“name” : “Syndicate Bank”,
“reference” : “CnRtAAAA_LbcYBdQ5KDQqNoHxaT2YLBfU5H6cnoi5MgcaFLHcGQQH6EAMKeNzi8KPtNjoTE1d1nBftN0a100yFJ5V103RWO6zZgfsJCb1D33A8DIyr6DyBm4CXOhjECWv5RPf3oriP2WbmQ5U5o8JzloTFApaBIQRZlVXmu5Npmx9SvoQ4a7kBoUzlHi7IgB3JtUAXo8WWCPhi_VQRI”,
“types” : [ “bank”, “finance”, “establishment” ],
“vicinity” : “Kesavadasapuram, Thiruvananthapuram”
}

],
“status” : “OK”
}

You can deserialize in to objects using JSON.NET

The class format should be

public class GooglePlacesResponse
{
public string status { get; set; }
public results[] results { get; set; }
}

public class results
{
public geometry geometry { get; set; }
public string name { get; set; }
public string reference { get; set; }
public string vicinity { get; set; }
}

public class geometry
{
public location location { get; set; }
}

public class location
{
public string lat { get; set; }
public string lng { get; set; }
}

Download json string and Deserialize using JsonConvert class in JSON.NET

WebClient wc = new WebClient();
string jsonStr = wc.DownloadString("https://maps.googleapis.com/maps/api/place/search/json?location=" + currentLoc + "&radius=50000&sensor=false&key=Your_Key&types=" + value);
GooglePlacesResponse gpr = (GooglePlacesResponse)JsonConvert.DeserializeObject<GooglePlacesResponse>(jsonStr);

Image
Happy deserializing:)