Water/ Not Water – Hacking the Google Maps API

This is the second post on mentorship at Iolani High School. Read part one if you’re interested in learning more about the mentorship.

The second page she was tasked with creating would allow users on the web to direct the catamaran to a specific GPS coordinate. In order to make sure users didn’t put in a GPS coordinate that was on land, she needed to determine if the input GPS coordinate was in the water.

She emailed me to ask for help:

I’m working on the control page now, and I am trying to figure out how to detect water on Google Maps. I have to make sure that the locations sent to the CAT are actually in the Ala Wai Canal. Since the Ala Wai Canal and other bodies of water show up as blue in Google Maps, I think that there should be a way to determine whether a location is in water or not. I’ve done some research on it and most pages suggest using reverse geocoding, however, I’m not sure it will work in this case. Here’s one website:
I clicked on the link to stackoverflow and read that the reverse geocoding wouldn’t work for this issue. So I dug into the second solution proposed. This seems absurd. Here’s the solution posted on stackoverflow:

These are steps your service must perform:

  1. Receive latitude,longitude and current zoom from client.
  2. Send http://maps.googleapis.com/maps/api/staticmap?center={latitude,longitude}&zoom={current zoom`}&size=1×1&maptype=roadmap&sensor=false request to Google Static Map service.
  3. Detect pixel’s color of 1×1 static image.
  4. Respond an information about detection.

You can’t detect pixel’s color in client side. Yes , you can load static image on client’s machine and draw image on canvas element. But you can’t use getImageData of canvas’s context for getting pixel’s color. This is restricted by cross domain policy.

Prons – Highly accurate detection

Cons – Use of own server resources for detection

Let’s go over how this works again to make sure you understand how hacky this solution is.

  1. Sign up for the Google Maps API
  2. Create a webpage in PHP
  3. Pass the GPS coordinates to the PHP page as GET parameters
  4. Send the GPS coordinates to Google
  5. Get back a 10 pixel by 10 pixel image of the map
  6. Process that image with PHP to determine what color it is
  7. If it’s blue it’s water
  8. If it’s any other color it is not water

I smiled all day after this project. It’s such a silly little solution. And it may break if Google changes the color of water in their map. But it works! I messaged back the student:

Thanks for the email. This was a really interesting problem! I ended up coding an API endpoint to determine if a latitude and longitude coordinate is WATER or is NOT WATER with the second option you linked to on stackoverflow.

Specifically this section:These are steps your service must perform:

Receive latitude,longitude and current zoom from client.

Send http://maps.googleapis.com/maps/api/staticmap?center={latitude,longitude}&zoom={current zoom`}&size=1×1&maptype=roadmap&sensor=false request to Google Static Map service.

Detect pixel’s color of 1×1 static image.

Respond an information about detection.

You can test the solution with the following calls:
 
Waikiki land: (returns NOT WATER) <link removed>
Pacific Ocean: (returns WATER) <link removed>
Ala Wai: (returns WATER) <link removed>
I am sharing the link with you to show that it works. I will be taking this code down at the end of the week so it is not possible to use this for your project. I would like to show you how to create this code for your project on your own machine. I’m free to meet in person or to help you via email or phone.
Here are the steps you need to take to set it up:
  1. Sign up for the Google Maps API
  2. Set up billing (this requires a credit card)
  3. Host the API code on a server with PHP
Let me know how you’d like to proceed
We’re meeting on Tuesday to get this set up and running on her webserver. This was such a fun project that I just had to post about it. Here is the code I created to solve this issue:

<?php

///////////////////// Gets the image from Google Maps API&lt;/code&gt;

// Set up the page to take in GET variables
$latitude = $_GET["latitude"];
$longitude = $_GET["longitude"];

// echo $latitude;
// echo "
";
// echo $longitude;

// Sets up parameters for call
$mapsApiKey = "";
$zoom = 20;

// Set up the API call
$apiCall = "https://maps.googleapis.com/maps/api/staticmap?center=" . $latitude . "%2c%20" . $longitude . "&amp;amp;zoom=" . $zoom . "&amp;amp;size=10x10&amp;amp;maptype=roadmap&amp;amp;sensor=false&amp;amp;key=" . $mapsApiKey;
// echo "
";
// echo $apiCall;

?>

document.addEventListener('DOMContentLoaded', function() {

// Gets the image from the API call
var apiCall = '';
// alert(apiCall);

// Set image source as constructed API call string
var img = new Image;
img.crossOrigin = "anonymous"; // To fix the security issue of reading images from other sources
var src = apiCall;

// Sets up the canvas
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");

// Fill in the backgorund color with red so we can see it
// ctx.fillStyle = "#FF0000";
// ctx.fillRect(0, 0, 10, 10);

// // Download the image
img.onload = function() { // ...then set the onload handler...
ctx.drawImage(img, 0, 0);

// Get color of image
var imgData = ctx.getImageData(0, 0, 1, 1);
var red = imgData.data[0];
var green = imgData.data[1];
var blue = imgData.data[2];
var alpha = imgData.data[3];

// Hides the canvas as we are not interested in seeing it
canvas.style.display="none";

console.log("red: " + red + " green: " + green + " blue: " + blue + " alpha: " + alpha);

// Determine if this response is WATER or NOT WATER
if (red == 170 &amp;amp;&amp;amp; green == 218 &amp;amp;&amp;amp; blue == 255) {
document.getElementById("findings").innerHTML = "WATER";
} else {
document.getElementById("findings").innerHTML = "NOT WATER";
}
};
img.src = src; // because the internet says you should put your src after your load

}, false);

Advertisements

Rules for Reading More

I read some of these book reviews and takeaway posts at the marketing meetings at work. When I finished reading the latest one, someone asked me how I read so much. “Do you read a book a week?” I shared a quick tip, “It’s important to have about 7 books going at the same time to make sure you don’t get bored with any one book.”

This question kept popping into my mind as the week went on. Finally, I sat down and came up with a list of ways I push myself to read more to share with the marketing team.

Here’s my list of rules for reading more. First I’ll sum them up. Then I’ll list each one out and elaborate on why it made it onto this list. Here we go.

Rules for Reading More:

  1. Read at least 5-7 books at a time.
  2. Stick to the “10 pages or I’m out” rule.
  3. Diversify your reading collection.
  4. Go for a chapter then take a break.
  5. Set a timer and stick to it.

Read at least 5-7 books at a time.

That way you won’t get bored with any particularly boring chapter in a book. Here’s a list of the books I’m currently reading. Notice the mix of non-fiction and fiction:

Stick to the “10 pages or I’m out” rule.

Someone suggested that I read “Sound and the Fury” by William Faulkner. It’s a book that I’ve heard a lot of great things about but I had never read it. So I borrowed it from the library. Then I started to read it. Very dry, very archaic, ultimately boring.

Never stick with a book that can’t hold your attention for the first 10 pages. If the writer didn’t invest enough effort to make the first 10 pages as compelling as possible, there’s a good chance he won’t have put in enough effort to keep your interest on page 100. Sorry Mr. Faulkner. No time.

Diversify your reading collection.

Do you love non-fiction books because you can apply their wisdom to your life? Get a compelling fiction book like “Ready Player One” by Ernest Cline to balance it out. You want to give your brain a rest after it’s been too deep into the non-fiction books.

Video games are made up of really tough sections moderated by very easy sections to keep you playing. Think about reading like this. Do the heavy lifting, then switch up to tiny fiction weights to give your brain a rest and let your soul feast.

Go for a chapter then take a break.

There’s a famous book on writing called “Bird by Bird” by Anne Lamont. The book gets its name from a story the author tells about her little brother in middle school. He needed to write a report on the 50 state birds.

He waits until the night before it’s due to start the paper and he’s miserable. Just as he’s about the give up, his dad gives him some simple advice, “Take it bird by bird.” In the same way, don’t look at the book as 300 pages, look at it as 30 chapters, broken up for you to take breaks between long stretches of reading.

Keep in mind that this is not a hard and fast rule. If you’re reading a chapter and just can’t make it, cut yourself some slack. Even if you read a single page it’s good enough. Don’t burn out with reading. Be kind to yourself.

Set a timer and stick to it.

Buddhist meditators set a timer for themselves sometimes. The timer isn’t set to tell them when the sitting is finished. No, it’s actually a more subtle maneuver.  They set the timer so that when they do the meditation they know that they owe the world nothing for this solid hour.

By setting a timer you don’t need to attend to anything else in the world. Everything can manage without your thinking and attention for 1 hour. In setting this timer, you are allowing yourself full access to the task at hand.

Finally, here’s the list again:

  1. Read at least 5-7 books at a time.
  2. Stick to the 10 pages or I’m out rule.
  3. Diversify your reading collection.
  4. Go for a chapter then take a break.
  5. Set a timer and stick to it.

I hope this list has helped you learn how to read more. It works for me. I’m always looking to add to this list so if you have any other tips that might help me out and contact me!

The most important contribution of a collaborator is to serve as an enthusiastic audience

51ejbnxvrl._ac_us218_Today I wanted to post about collaborative circles. At work I’m part of the marketing team. All members have diverse talents. We collaborate together to make the team greater than the sum of its parts.

In collaborative situations, the goals don’t seem as clear as I’d like them to be. That’s why I enjoyed reading “Collaborative Circles – Friendship Dynamics and Creative Work” by Michael P. Farrell

The book starts out with the adage, nearly the same as Steve Jobs is quoted saying: “Great things in business are never done by one person. They’re done by a team of people.”

“The best things come … from the talents that are members of a group; every man works better when he has companions working in the same line, and yielding to the stimulus of suggestion, comparison, emulation. Great things have of course been done by solitary workers, but they have usually been done with double the pains they would have cost if they had been produced in more genial circumstances. – Henry James”

The most important thing that prevents collaboration from happening is a closed off group that is dominated by a single gate keeper.

“If communication within a friendship group is open, if the members are not dominated by a defensive mentor anxious to preserver a particular vision of the field, the interaction in the group may start percolating toward a new vision.” – Farrell

The biggest insight regarding collaboration comes halfway through the book. Ever been paired off for group work in a class only to find that your collaborators were pessimistic Eeyores?

“One of the most important contributions of a collaborator is to serve as an enthusiastic audience. A respected peer who serves as admiring but demanding audience can be a powerful stimulus to creative work. When the mirroring other takes the creative person seriously, attends to small advances, and responds with appreciative criticism, the person becomes more centered and invests more in the creative process.” – Farrell

So what’s the formula for a productive collaborative circle?

“The center coalition consists of the members who consolidate the insights that emerge within collaborative pairs, integrate them into a coherent theory , and convey the vision to newcomers into the circle.” – Farrell

And finally, why can’t we meet online instead of in-person?

“Internet communication may facilitate the formation of circles, and it may enable them to maintain contact between meetings, but I do not think it allows for the kind of in-depth dialogue that leads to meaningful personal development and creative work. For this kind of interaction, there is no substitute for ritualized meetings and working side by side.” – Farrell

I hope these insights clarify the role you play in a collaborative group. To summarize the suggestions for better collaboration, stick to these goals:

  • Work in groups: Great things have been done by solitary workers but they have usually been done with double the pains they would have cost if they had been produced in more genial circumstances
  • Be open: Keep out the defensive mentors and anxious preservers
  • Be enthusiastic: Sometimes being the best collaborator is being an enthusiastic audience
  • Meet in-person: In-person meetings allow for in-depth dialogue that’s required for meaningful personal development and creative work.

Did this help clarify the role collaborative circles play in creative work? Contact me I’d love to hear about it.

Mindfulness is the willingness to turn toward our experience

41CASF11djL._AC_US218_Today I’ll be posting on Judson Brewer’s “The Craving Mind.” This book has a bunch of good ideas regarding how to curb your social media use.

A lot of habit-breaking advice recommends mindfulness. This usually means, “If I am aware of what I am doing, I won’t indulge in bad habits.” But what if there’s more to the meaning of mindfulness than you think?

In “The Craving Mind.” Brewer clarifies the role or mindfulness in stopping our bad habits:

“Mindfulness is just about being interested in, and getting close and personal with, what is happening in our bodies and minds. It is really this willingness to turn toward our experience rather than to try to make our unpleasant cravings go away as quickly as possible.” – Brewer

Human beings are very bad at turning toward their experiences rather than trying to make their unpleasant cravings go away as quickly as possible.

In a study, participants were asked to stay in a quiet room by themselves for 20 minutes. They weren’t allowed access to any of their usual distracting devices – no smartphones, no tv, no radio. All they had was a tiny device that delivered an electrical shock when the participant pushed a button.

Here’s the surprising thing. The majority of the participants used the device to shock themselves and keep themselves entertained rather than face their own solitary thoughts. Let me repeat: they rather shock themselves than be forced to listen to their own thoughts!

If mindfulness is more than the awareness of your thoughts, it is the willingness to turn toward our experience rather than trying to make our unpleasant cravings go away as quickly as possible. How do we prepare ourselves for this willingness?

Everyone’s on social media. But not everyone posts. I believe the first step to turning toward our experience is to be mindful of what you get from posting to Social Media:

“We learn to go online or post something to our social media sites in order to get the reward that indicates we are relevant, we matter. Each time we are assured, we get reinforced, the loneliness is dissipated, and the connection feels good. We learn to come back for more.” – Brewer

Mindfulness works to curb your addictions by giving yourself enough time, energy, and space to examine just why you are taking part in them. The first step is calming your mind and sorting your thoughts.

“A human mind is a wandering mind, and a wandering mind is an unhappy mind.” – Brewer

Brewer goes into more detail to describe the process of observing and being mindful to curb addictive behaviors.

“We taught people to pay attention to their habit loops so that they would become disenchanted with their previous behaviors by seeing clearly what rewards they were actually getting. Target craving and you can conquer an addition. And this targeting of craving was not through brute force but, counter-intuitively, through turning toward or getting close to it. Through direct observation, we can become as the term ‘asava’ is translated, less intoxicated.” – Brewer

So if you still feel bad about yourself for posting on social media, remember this quote,

“Ego, the self which he has believed himself to be, is nothing but a pattern of habits.” – Alan Watts

Change your habits, change your life. Did this post help to clarify the role of mindfulness is curbing your Social Media habit? Contact me, I’d love to hear about it.

The Storybrand 7 (SB7) framework

In the last post on “Building a Story Brand – Clarify Your Message So Customers Will Listen,” I shared that most businesses fail to distinguish themselves as guides. They make the mistake of posing as heroes and turn away the potential heroes they are trying to help.

In this post I’d like to outline the seven steps in the Storybrand 7 framework. Donald Miller suggest using this guide to steer your heroes through their path to greatness. After I list out the seven steps in the Storybrand 7 framework, I’ll go into further details regarding each step.

Here’s the SB7 framework:

  1. A character – The customer is the hero.
  2. Has a problem – Successful companies attend to their inner frustrations.
  3. And meets a guide – The customers are looking for a guide.
  4. Who has a plan – Customers trust a guide who has a plan.
  5. And calls them to action – Customers are challenged to take action.
  6. That helps them avoid failure – Everyone is trying to avoid a tragic ending.
  7. And ends in a success – This principle shows people how the product can positively influence their lives.

Now that we have the 7 steps listed out, let’s dig in and go deeper.

A character

“Nobody will listen to you if your message isn’t clear, no matter how expensive your marketing material may be.” – Donald Miller

You need to identify and be clear about who you are attempting to help. Targeting everyone is like targeting no one. What kind of change do you want to affect? You need to strictly define who you are helping.

Has a problem

“The only reason our customers buy from us is because the external problems we solve are frustrating them in some way. If we can identify that frustration, put it into words, and offer to resolve it along with the original external problem, something special happens. We bond with our customers because we’ve positioned ourselves more deeply into their narrative.” – Donald Miller

If you can’t define the problem the user if facing, how will you know you’ve been effective. The first step in helping is clarifying the problem the hero is facing.

And meets a guide

“The guide doesn’t have to be perfect, but the guide needs to have serious experience helping other heroes win the day.” – Donald Miller

A helpful guide has been through the same problems the hero has faced. He offers advice and wisdom. All advice is hindsight. Guides share what they would have done differently, had they known better at the time.

Who has a plan

“The key to the success of any plan is to alleviate confusion for our customers. What steps do they need to take to do business with you? Spell out those steps, and it’ll be as though you’ve paved a sidewalk through a field. More people will cross the field.” – Donald Miller

Make sure you make the hero know why you are suggested the path you are suggesting. If they don’t agree with the trajectory you’re sending them on with this plan, go back to step 2 and redefine the problem until the hero agrees on the trajectory of the solution.

And calls them to action

“People are drawn to clarity and away from confusion. Having clear calls to action means customers aren’t confused about the actions they need to take to do business with you.” – Donald Miller

Nothing happens unless you act on your plan. A guide may motivate the hero but they can’t force him/her to act. As the saying goes, “Leap and the net will appear.”

That helps them avoid failure

“Brands that don’t warn their customers about what could happen if they don’t buy their products fail to answer the so what questions every customer is secretly asking.” – Donald Miller

Knowing what could happen if no action is taken is required to motivate the hero to act on the plan you’ve collaboratively set up.

And ends in a success

“People are drawn to transformation. When they see transformation in others, they want it for themselves. The more we feature the transformative-journey our customers have experienced, the faster our business will grow.” – Donald Miller

I hope that the Storybrand 7 framework clarifies the explicit steps you must take to guide your heroes through their inevitable journey. Contact me if you have any questions.