Open Native Google Maps App from Phonegap / Cordova (iOS)

If you want to show a map in your Phonegap app, you can always use the google maps API to show a map, or even use the in-app browser to link out to a google map page. But nothing quite matches the Google maps native app, with it’s funky satnav-like features, and slick interface

Thing is, the Google Maps App isn’t installed by default, so in this case, I’m failing-over to a in-App Browser version. This code is iOS only, but anyone wishing to provide a port to Android will be rewarded* (Yes, I’d pay for the port)

– (void) openGoogleMaps:(CDVInvokedUrlCommand *)command

{

NSLog(@”openGoogleMaps”);

NSString* callbackId = [command callbackId];

NSArray* arguments = [command arguments];

NSString* map = [arguments objectAtIndex:0];

CDVPluginResult* result;

NSURL *testURL = [NSURL URLWithString:@”comgooglemaps://”];

if ([[UIApplication sharedApplication] canOpenURL:testURL]) {

NSString *directionsRequest = [NSString stringWithFormat:@”%@%@”,

@”comgooglemaps://?” ,

map];

NSURL *directionsURL = [NSURL URLWithString:directionsRequest];

[[UIApplication sharedApplication] openURL:directionsURL];

result = [CDVPluginResult

resultWithStatus:CDVCommandStatus_OK

messageAsBool:true];

} else {

NSLog(@”Can’t use comgooglemaps:// on this device.”);

result = [CDVPluginResult

resultWithStatus:CDVCommandStatus_OK

messageAsBool:false];

}

[self success:result callbackId:callbackId];

}

Then, this is called from Javascript as follows:

function openGoogleMaps(route)

{

console.log(“openGoogleMaps”);

cordova.exec(function(data)

{

console.log(“Returned from google maps:” + data);

if (!data)

{

// Failed to find native app.

var strUrl = “http://maps.google.com/maps?”;

strUrl += route;

var ref = window.open(strUrl, “_blank”, “location=yes”);

}

}, function(data)

{

console.log(“Plugin failure”);

}, ‘StatusBar’, ‘openGoogleMaps’, [route]);

}

Categories: Uncategorized

Upload a file to Amazon S3 using C#

This code example is probably online a million times, but just to include it again here;

string existingBucketName = “mybucket”;
string filePath = @”c:\users\you\desktop\file.png”;
Amazon.Util.ProfileManager.RegisterProfile(“test”, “xxxxx”,”XXXX”);
AWSCredentials credentials = new StoredProfileAWSCredentials(“test”);
IAmazonS3 s3Client = new AmazonS3Client(credentials, RegionEndpoint.EUWest1);
TransferUtility fileTransferUtility = new TransferUtility(s3Client);
var uploadRequest = new TransferUtilityUploadRequest
{

FilePath = filePath,
BucketName = existingBucketName,
CannedACL = S3CannedACL.PublicRead
};
fileTransferUtility.Upload(uploadRequest);

Categories: Uncategorized

Capture hi-res image from iTunes using C#

This is a quick demo of how to use the iTunes API to extract the hi-res icon of any iOS app;

WebClient wc = new WebClient();
string strUrl = @”http://itunes.apple.com/search?term=” + HttpUtility.UrlEncode(tbSearch.Text) + “&entity=iPadSoftware”;
string strHtml = wc.DownloadString(strUrl);
const string strArtRegex = “artworkUrl100.:\”(.*?)\””;
Match mArt = Regex.Match(strHtml, strArtRegex);
string Url = mArt.Groups[1].Value;
imgArtwork.Src = Url;

This assumes a user interface somewhat like this:

<asp:TextBox runat=”server” ID=”tbSearch”></asp:TextBox>
<asp:Button runat=”server” ID=”btnSearch” OnClick=”btnSearchClick” Text=”Search”/>
<br/>
<img id=”imgArtwork” runat=”server”/>

Hope this helps someone.

Categories: Uncategorized

Favourite Tweets using C# Tweetsharp

If you want to make noise on twitter, favouriting people’s tweets does draw a little attention, so I decided to try to do this automatically, to see if I could build followers.- Here is the code I used in C# (authentication details removed) – you need a reference to TweetSharp

var service = new TwitterService(“########”, “######”);
service.AuthenticateWith(“###”, “#####”);
TwitterSearchResult res = service.Search(new SearchOptions { Q = args[0], Count = 100});
IEnumerable<TwitterStatus> status = res.Statuses;
foreach (var tweet in status)
{
Console.WriteLine(tweet.Text);
service.FavoriteTweet(new FavoriteTweetOptions{Id = tweet.Id});
}

It takes a command line argument, which it uses as a search term, so you can favourite tweets that are relevant.

And, hey if you want to follow me, please go to: https://twitter.com/webtropy

Categories: Uncategorized

2014 in review

Categories: Uncategorized

Read extended properties of a file in C#

You need to make a reference to the COM library “Microsoft Shell controls and automation”

[STAThread]
public static void Main(string[] args)
{
List<string> arrHeaders = new List<string>();

Shell32.Shell shell = new Shell32.Shell();
var strFileName = @”C:\Users\Fiach\Desktop\sample_iTunes.mov”;
Shell32.Folder objFolder = shell.NameSpace(System.IO.Path.GetDirectoryName(strFileName));
Shell32.FolderItem folderItem = objFolder.ParseName(System.IO.Path.GetFileName(strFileName));

for (int i = 0; i < short.MaxValue; i++)
{
string header = objFolder.GetDetailsOf(null, i);
if (String.IsNullOrEmpty(header))
break;
arrHeaders.Add(header);
}

for (int i = 0; i < arrHeaders.Count; i++)
{
Console.WriteLine(“{0}\t{1}: {2}”, i, arrHeaders[i], objFolder.GetDetailsOf(folderItem, i));
}
Console.ReadLine();
}

Categories: Uncategorized

HTTP POST using PHP

$url = ‘https://posttestserver.com/post.php&#8217;;
$data = array(‘key1’ => ‘value1’, ‘key2’ => ‘value2’);

// use key ‘http’ even if you send the request to https://&#8230;
$options = array(
‘http’ => array(
‘header’ => “Content-type: application/x-www-form-urlencoded\r\n”,
‘method’ => ‘POST’,
‘content’ => http_build_query($data),
),
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
echo($result);

—- And the cool thing is that posttestserver.com lets you see what you posted to it. cool service!

Categories: Uncategorized

WebOS app store apps released for free

Categories: Uncategorized

JQuery, Binding on nested element

In this simple example, there is a nasty bug

<html>
<head>
<script src=”http://code.jquery.com/jquery-1.11.0.min.js”></script&gt;
</head>
<body>
<div id=”outer” style=”background:red; width:400px; height:200px”>
<div id=”inner” style=”background:blue; width:200px; height:100px”>
</div>
</div>
<script>
$(init);
function init()
{
$(“#outer”).bind(“click”, outer_click);
$(“#inner”).bind(“click”, inner_click);
}
function outer_click(event){
alert(“outer click”);
}
function inner_click(event){
alert(“inner click”);
}
</script>
</body>
</html>

If you click on the blue square, then you get two alerts, one for the inner element, and one for the outer element.

The solution is to stop event bubbling, by including this on the inner_click

event.stopPropagation();

Categories: Uncategorized

A Hello World example for Foundation Reveal

Foundation is a Javascript / CSS framework similar to Bootstrap, and I was looking at the Reveal plugin to create modal dialogs, but dismayed when there was no really simple “hello world” example.

First, download Foundation “complete”, and then create a HTML file with this content

<html>
<head>
<link href=”css/foundation.css” rel=”stylesheet” />
<script src=”js/vendor/modernizr.js”></script>
<script src=”js/vendor/jquery.js”></script>
<script src=”js/foundation/foundation.js”></script>
<script src=”js/foundation/foundation.reveal.js”></script>
</head>
<body>

<a href=”#” id=”btnJoin” >Join</a>

<div id=”dialogPage” class=”reveal-modal” data-reveal>
<h2>Alert</h2>
<p id=”pMessage”></p>
<a class=”close-reveal-modal”>×</a>
</div>

<script>
$(init);
function init()
{
$(document).foundation();
$(“#btnJoin”).bind(“click”, btnJoin_click);
}

function btnJoin_click()
{
jqmAlert(“Hey, I’m an alert”);
}

function jqmAlert(message)
{
console.log(“jqmAlert(” + message + “)”);
$(“#pMessage”).html(message);
$(‘#dialogPage’).foundation(‘reveal’, ‘open’);
}
</script>
</body>
</html>

Categories: Uncategorized