Skip to content

Instantly share code, notes, and snippets.

void FnGeoCodeApi()
{
string strGeoCode = string.Format ("address={0}","Silicon Valley,CA,USA");
string strGeoCodeFullURL = string.Format (Constants.strGeoCodingUrl,strGeoCode);
string strResult=await FnHttpRequest(strGeoCodeFullURL);
if ( strResult != Constants.strException )
{
var objGeoCodeClass= JsonConvert.DeserializeObject<GoogleGeoCodeClass> (strResult);
if ( objGeoCodeClass.status == "OK" )
{
//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")
{
//rest request to google direction api
internal static string strGoogleDirectionUrl="https://maps.googleapis.com/maps/api/directions/json?origin=src_locn&destination=dest_lcn&key=keyGoesHere";
string strJSONDirectionResponse = await FnHttpRequest(strGoogleDirectionUrl);
var objRoutes = JsonConvert.DeserializeObject<GoogleDirectionClass> ( jSonData );
//find GoogleDirectionClass below in this page
//Draw line by connecting polyline points
UIColor pathColor = UIColor.Red;
int intRoutesCount=objRoutes.routes.Count;
//available routes may be more then one
for ( int intCounter = 0 ; intCounter < intRoutesCount ; intCounter++ )
{
var path = Google.Maps.Path.FromEncodedPath ( objRoutes.routes [intCounter].overview_polyline.points );
var line = Google.Maps.Polyline.FromPath ( path );
line.StrokeWidth = 3f;
line.StrokeColor = UIColor.Red;
//Google GeoCode class
public class AddressComponent
{
public string long_name { get; set; }
public string short_name { get; set; }
public List<string> types { get; set; }
}
public class Northeast
{
public double lat { get; set; }
//GoogleDirectionClass.cs
public class GeocodedWaypoint
{
public string geocoder_status { get; set; }
public string place_id { get; set; }
public List<string> types { get; set; }
}
public class Northeast
{
public double lat { get; set; }
//customized snackbar
void fnSnackBar( string strText,bool isLengthIndefinite)
{
Snackbar objSnackBar = Snackbar.Make (linearLayoutMain, strText, isLengthIndefinite ? Snackbar.LengthIndefinite : Snackbar.LengthShort)
.SetAction (Resource.String.retry, (v) => {
//set action
});
//set action button text color
objSnackBar.SetActionTextColor(Android.Graphics.Color.Aqua);
@suchithm
suchithm / FrameRenderer.cs
Last active November 21, 2016 17:43
FrameRenderer
using Android.Graphics;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using ACanvas = Android.Graphics.Canvas;
using Color = Android.Graphics.Color;
[assembly: ExportRenderer(typeof(Frame), typeof(FrameBugPoc.Droid.FrameRenderer))]
namespace FrameBugPoc.Droid
{
public class FrameRenderer : Xamarin.Forms.Platform.Android.FrameRenderer
@suchithm
suchithm / RoundedCornerFrameRenderer.cs
Created November 21, 2016 16:23
Frame Renderer class
using System;
using Xamarin.Forms;
using Xamarin.Forms.Platform.Android;
using System.ComponentModel;
using Android.Graphics;
using Android.Graphics.Drawables;
using AButton = Android.Widget.Button;
using ACanvas = Android.Graphics.Canvas;
using GlobalResource = Android.Resource;
@suchithm
suchithm / rounded_corner_background.xml
Created November 21, 2016 16:26
Selector xml with rounded corner
<?xml version="1.0" encoding="UTF-8" ?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="1dp"
android:color="#252525"/>
<corners android:radius="5dp" />
<solid android:color="#FFFFFF" />
</shape>