public GoogleMap getGeoCode(String location)
        {
            GoogleMap pointer = new GoogleMap();
            try
            {

                String searchURL = "http://dev.virtualearth.net/REST/v1/Locations/" + location + "?o=json&key=AoAtLFi1vWDNZpOvpHF-2-S71qWRTg1s_vu5LHGFGrw_v0jA4b0rqmHuuj0cF-8Y";
                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(searchURL);

                WebResponse webResponse = request.GetResponse();
                Stream webStream = webResponse.GetResponseStream();
                StreamReader responseReader = new StreamReader(webStream);
                string response = responseReader.ReadToEnd();

                Geocoding.Rootobject referenceObbj = JsonConvert.DeserializeObject<Geocoding.Rootobject>(response);

                if (referenceObbj.resourceSets[0].estimatedTotal != 0)
                {
                    pointer.latitude = referenceObbj.resourceSets[0].resources[0].point.coordinates[0] + "";
                    pointer.longitude = referenceObbj.resourceSets[0].resources[0].point.coordinates[1] + "";
                    pointer.bbox = referenceObbj.resourceSets[0].resources[0].bbox;
                }
            }
            catch (Exception ex)
            {
                trafficInfo.error += location;
                trafficInfo.error += ex.StackTrace.ToString();

            }
            finally
            {

            }
            return pointer;
        }
        public String getJScript(GoogleMap marker)
        {
            String result = "";
            if(marker.latitude!=""||marker.latitude!=null)
            {
                result += "var myLatlng = new google.maps.LatLng(" + marker.latitude + "," + marker.longitude + ");";

            }
            return result;
        }
        public List<Traffic.Resource> getTrafficInfo(String location)
        {
            List<Traffic.Resource> traffic=new List<Traffic.Resource>();
            GoogleMap gMap = getGeoCode(location);
            String url = "http://dev.virtualearth.net/REST/v1/Traffic/Incidents/" + gMap.bbox[0] + "," + gMap.bbox[1] + "," + gMap.bbox[2] + "," + gMap.bbox[3] + "?o=json&key=AoAtLFi1vWDNZpOvpHF-2-S71qWRTg1s_vu5LHGFGrw_v0jA4b0rqmHuuj0cF-8Y";
            Traffic.Rootobject referenceObbj = null;
            try
            {

                HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);

                WebResponse webResponse = request.GetResponse();
                Stream webStream = webResponse.GetResponseStream();
                StreamReader responseReader = new StreamReader(webStream);
                string response = responseReader.ReadToEnd();

                referenceObbj = JsonConvert.DeserializeObject<Traffic.Rootobject>(response);

                GoogleMap google = null;
                foreach (Traffic.Resource resource in referenceObbj.resourceSets[0].resources)
                {
                    traffic.Add(resource);

                    google = new GoogleMap();
                    google.latitude = resource.point.coordinates[0] + "";
                    google.longitude = resource.point.coordinates[1] + "";
                    google.description = resource.description.Replace("'", ""); ;
                    if (resource.severity == 1)
                    {
                        google.description += "\\n Severity: Low Impact";
                    }
                    else if (resource.severity == 2)
                    {
                        google.description += "\\n Severity:Minor";
                    }
                    else if (resource.severity == 3)
                    {
                        google.description += "\\n Severity: Moderate";
                    }
                    else if (resource.severity == 4)
                    {
                        google.description += "\\n Severity: Serious";
                    }

                    if (resource.type == 1)
                    {
                        google.description += "\\n Type: Accident";
                    }
                    else if (resource.type == 2)
                    {
                        google.description += "\\n Type: Congestion";
                    }
                    else if (resource.type == 3)
                    {
                        google.description += "\\n Type: Disabled Vehicle";
                    }
                    else if (resource.type == 4)
                    {
                        google.description += "\\n Type: Mass Transit";
                    }
                    else if (resource.type == 5)
                    {
                        google.description += "\\n Type: Miscellaneous";
                    }
                    else if (resource.type == 6)
                    {
                        google.description += "\\n Type: Other News";
                    }
                    else if (resource.type == 7)
                    {
                        google.description += "\\n Type: Planned Event";
                    }
                    else if (resource.type == 8)
                    {
                        google.description += "\\n Type: Road Hazard";
                    }
                    else if (resource.type == 9)
                    {
                        google.description += "\\n Type: Construction";
                    }
                    else if (resource.type == 10)
                    {
                        google.description += "\\n Type: Alert";
                    }
                    else if (resource.type == 11)
                    {
                        google.description += "\\n Type: Weather";
                    }

                    if (resource.roadClosed)
                    {
                        google.description += "\\n Road Closed";
                    }
                    gPointers.Add(google);
                }
            }
            catch (Exception ex)
            {
                //url= ex.Source.ToString();
                //url += ex.StackTrace.ToString();
                // output.error += location;
                //  output.error += ex.Message.ToString();
                //output.error += ex.Data.ToString();
                // output.error += ex.StackTrace.ToString();
            }

            return traffic;
        }
        List<GoogleMap> getGoogleMapServicePointers(List<Yelp.Business> bList)
        {
            String description = "";
               List<GoogleMap> gPlotList = new List<GoogleMap>();
               GoogleMap google = null;
            foreach(Yelp.Business business in bList)
               {
                    google = new GoogleMap();
                    description = "";
                    description += "" + business.name.Replace("'", "") + "";
                    description += "\\n " + business.address1.Replace("'", "");
                    description += "\\n " + business.address2.Replace("'", ""); ;
                    description += "\\n " + business.city.Replace("'", ""); ;
                    description += "\\n Rating: " + business.avg_rating;
                    description += "\\n Phone " + business.phone.Replace("'", ""); ;

                String locationInfo="";

                if((business.address1!=""||business.address1!=null))
                {
                    locationInfo = business.address1.Replace(" ", "%20");
                    locationInfo+=",";
                }

                if (business.address2 != "" || business.address2 != null)
                {
                    locationInfo += business.address2.Replace(" ", "%20");
                    locationInfo += ",";
                }

                if (business.address3 != "" || business.address3 != null)
                {
                    locationInfo += business.address3.Replace(" ", "%20");
                    locationInfo += ",";
                }

                if (business.city != "" || business.city != null)
                {
                    locationInfo += business.city.Replace(" ", "%20");
                    locationInfo += ",";
                }

                if (business.state != "" || business.state != null)
                {
                    locationInfo += business.state.Replace(" ", "%20");
                    locationInfo += ",";
                }

                if (business.country != "" || business.country != null)
                {
                    locationInfo += business.country.Replace(" ", "%20");
                }
                locationInfo = locationInfo.Replace(" ", "%20");
                locationInfo = locationInfo.Replace(",,", ",");

                     google = getGeoCode(locationInfo);
                     google.description = description;
                     google.id = business.id;
                     gPlotList.Add(google);

                }
               return gPlotList;
        }
        public List<GoogleMap> getServicePointsAlongRoute(GoogleDirections.TDirections directionsObj)
        {
            bool flag = false;
            int size = directionsObj.routes[0].legs[0].steps.Length;
            GoogleDirections.Step[] tLegs=directionsObj.routes[0].legs[0].steps;
            GoogleDirections.Step pointer = null;
            int incrementSize = size / 5;
            incrementSize = incrementSize-1;
            List<GoogleMap> pointerList = new List<GoogleMap>();
            GoogleMap gMap = null;
            for(int i=0;i<tLegs.Length;i++)
            {
                if(i==tLegs.Length-1)
                {
                    flag = true;
                }
                pointer = tLegs[i];
                gMap = new GoogleMap();
                gMap.latitude=pointer.start_location.lat+"";
                gMap.longitude=pointer.start_location.lng+"";

                gMap.elatitude = pointer.end_location.lat + "";
                gMap.elongitude = pointer.end_location.lng + "";

                pointerList.Add(gMap);
            }
            if(!flag)
            {
                gMap = new GoogleMap();
                gMap.latitude = tLegs[tLegs.Length-1].end_location.lat + "";
                gMap.longitude = tLegs[tLegs.Length - 1].end_location.lng + "";

                pointerList.Add(gMap);
            }
            return pointerList;
        }