Last active
September 3, 2015 12:30
-
-
Save suchithm/01d240225127d521815b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Code snippet to mark source and destination points | |
Location SourceLocation{get;set;} | |
Location DestinationLocation{get;set;} | |
//mark source point | |
strGeoCodeURL =string.Format ("https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}",strSource,"ApiKeygeoeshere"); | |
string strHttpResponse= await FnHttpRequest (strGeoCodeURL); | |
GeoCodeJSONClass objGeoCodeJSONClass = JsonConvert.DeserializeObject<GeoCodeJSONClass> (strHttpResponse); | |
//find GeoCodeJSONClass below in this page | |
if(objGeoCodeJSONClass!=null && objGeoCodeJSONClass.status=="OK") | |
{ | |
SourceLocation=new Location(){lat=objGeoCodeJSONClass.results[0].geometry.location.lat,lng=objGeoCodeJSONClass.results[0].geometry.location.lng}; | |
MarkOnMap (SourceLocation,"Start",UIImage.FromBundle("Images/MarkerSource"),false); | |
} | |
//mark destination point | |
strGeoCodeURL =string.Format ("https://maps.googleapis.com/maps/api/geocode/json?address={0}&key={1}",strDestination,"apiKeygeoeshere"); | |
string strHttpResponse = await FnHttpRequest ( strGeoCodeURL ); | |
var objGeoCodeJSONClass = JsonConvert.DeserializeObject<GeoCodeJSONClass> (strHttpResponse); | |
if ( objGeoCodeJSONClass != null && objGeoCodeJSONClass.status == "OK" ) | |
{ | |
DestinationLocation = new Location () { lat = objGeoCodeJSONClass.results [0].geometry.location.lat, lng = objGeoCodeJSONClass.results [0].geometry.location.lng }; | |
MarkOnMap ( DestinationLocation , "End" , UIImage.FromBundle ( "Images/MarkerDest" ) , false ); | |
} | |
void MarkOnMap(Location location,string strTitle,UIImage imgIcon,bool isFlat) | |
{ | |
var marker = new Marker (); | |
marker.Flat = isFlat; | |
marker.Position = new CLLocationCoordinate2D ( location.lat , location.lng ); | |
marker.Map = mapView; | |
marker.Title = strTitle; | |
marker.Icon=imgIcon; | |
marker.Draggable=false; | |
marker.AppearAnimation=MarkerAnimation.Pop; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//HttpWebRequest common method | |
static async Task<string> FnHttpRequest(string strURL) | |
{ | |
WebClient client = new WebClient (); | |
string strResult; | |
try | |
{ | |
strResult=await client.DownloadStringTaskAsync (new Uri(strURL)); | |
} | |
catch | |
{ | |
strResult="Exception"; | |
} | |
finally | |
{ | |
client.Dispose (); | |
client = null; | |
} | |
return strResult; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment