Category Archives: project

GMap.NET component : Moving Marker

WTH is GMap.NET?

Simply put: it’s an open source .net component that can show online mapping service (such as Google Map, Bing Map, OpenStreetMap) in your .NET app.
Download the binary here:
Extract it. You’ll get the .net 2.0 and .net 4.0 version, since I’m using VS 2015, we’ll use the .net 4.0 version.

What will we do now is about how to move a marker inside the map (for tracking/visualizing object movement, etc). We’ll just move the marker randomly in this tutorial.

  • Create new VB Windows Form project
  • Add GMap.NET component into your project reference
GMap.NET component reference

GMap.NET component reference

  • Add GMap.NET component into your toolbar.
Add GMap.NET component step 1

Add GMap.NET component step 1

Add GMap.NET component step 2

Add GMap.NET component step 2

  • Now drag and drop the GMap.NET control into your Form, I name it myMap
  • We’ll also add another controls: 1 Button (name: btnMove), 1 Timer (name: tmr1), 1 Label (name: lblInfo)
List of components

List of components

I also add new bitmap resource into our project properties. This will be used as our marker symbol.

Resource for marker symbol

Resource for marker symbol

You can see the Form’s full source code at the bottom of this post. I’ll just point out some important parts:

  • Map initialization is on Form1_Load event code (zoom level, initial position, provider used, marker type, etc)
  • When you click on the btnMove, it’ll start generating new random position for our marker. The random change is happened in the timer event (tmr1_Tick)
  • The process to update the map visual is delegated into function update_map(), so it will run in different thread and the form still responsive
  • In this tutorial, we are using BingSatelliteMapProvider, you can use another provider such as GoogleMapProvider or OviSatelliteMapProvider. Just see MapProviders namespace to see all supported providers.

Running the app

Running the app

Here’s the full source code:

Imports GMap.NET
Imports GMap.NET.WindowsForms

Public Class Form1
    Private Delegate Sub UpdateFormDelegate()
    Private UpdateFormDelegate1 As UpdateFormDelegate

    Private copter_lat, copter_lon As Double
    Private WithEvents copter_marker As Markers.GMarkerGoogle
    Private WithEvents copter_layer As GMapOverlay

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        copter_lat = -7.076275
        copter_lon = 110.428952

        myMap.MinZoom = 5
        myMap.MaxZoom = 20
        myMap.Zoom = 17
        myMap.Position = New PointLatLng(-7.076275, 110.428952)
        myMap.MapProvider = MapProviders.BingSatelliteMapProvider.Instance
        myMap.Manager.Mode = AccessMode.ServerAndCache
        copter_layer = New GMapOverlay("copter_layer")
        copter_marker = New Markers.GMarkerGoogle(New PointLatLng(-7.076275, 110.428952), My.Resources.purple_drone)
    End Sub

    Private Sub tmr1_Tick(sender As Object, e As EventArgs) Handles tmr1.Tick
        Dim delta_lat As Double = ((100 * Rnd()) + 20) / 10000000.0
        Dim delta_lon As Double = ((100 * Rnd()) + 20) / 10000000.0
        Dim not_lat As Single = Rnd()
        Dim not_lon As Single = Rnd()

        If not_lat >= 0.5 Then
            copter_lat += delta_lat
            copter_lat -= delta_lat
        End If
        If not_lon >= 0.5 Then
            copter_lon += delta_lon
            copter_lon -= delta_lon
        End If

        UpdateFormDelegate1 = New UpdateFormDelegate(AddressOf update_map)
    End Sub

    Private Sub btnMove_Click(sender As Object, e As EventArgs) Handles btnMove.Click
        If tmr1.Enabled Then
            tmr1.Enabled = False
            MsgBox("Random Move stop")
            tmr1.Enabled = True
            MsgBox("Random Move start")
        End If
    End Sub

    Private Sub myMap_OnMapZoomChanged() Handles myMap.OnMapZoomChanged
        lblInfo.Text = "Info : Lat= " + CStr(copter_lat) + ", Lon= " + CStr(copter_lon) + ", Zoom Level= " + CStr(myMap.Zoom)
    End Sub

    Private Sub update_map()
        copter_marker.Position = New PointLatLng(copter_lat, copter_lon)
        lblInfo.Text = "Info : Lat= " + CStr(copter_lat) + ", Lon= " + CStr(copter_lon) + ", Zoom Level= " + CStr(myMap.Zoom)
    End Sub
End Class

Exporting high resolution image from QGIS project



You want to export your QGIS project into high resolution image. QGIS desktop “Project” –> “Save as Image” only save/export the project into a low resolution image (i.e. your desktop resolution).



1. Finish your project in QGIS

Finish your GIS project in QGIS Desktop, choose which layers to be shown, what style should it use, etc.

2. Choose your extent that will be exported into image

For myself, I choose the full-extent, but you may choose the extent as you wish. You my use “Vector” –> “Coordinate Capture” to help copying the coordinates. You will need to write down the coordinates for [xMin, yMin] (top-left coordinate) and for [xMax, yMax] (bottom-right coordinate). Save and close your QGIS project.

3. Execute the export command via command line of QGIS

Open your command prompt/console (preferably as Administrator/root). Go to your QGIS binary folder, where you install QGIS +”bin” folder, for example C:\Program Files\QGIS Brighton\bin. Use this command template:

qgis --project "c:\where\you\save\your\qgis\project\file.qgs" --snapshot "c:\where\you\want\to\save\your\image.png" --height result_image_height --width result_image_width --extent xmin,ymin,xmax,ymax

For example:

C:\Program Files\QGIS Brighton\bin>qgis --project "D:\work\dita s1\pmapper\Semarang\Kec_Banyumanik\banyumanik.qgs" --snapshot "c:\users\achmadz\documents\padangsari.png" --height 5000 --width 5000 --extent 435825.86153,9218725.47861,438150.22840,9217277.65534

That command will open QGIS Desktop for a moment then close itself. The command will produce padangsari.png in c:\users\achmadz\documents\. Open the image, and you’ll see the image in high resolution (5000×5000 pixels).


[php] New Bing SERP checker using Windows Azure Datamarket

So, I got email from Bing Developer Team informing that Bing Search API 2.0 will be gone and moving to new platform: Windows Azure Datamarket. On my previous Bing SERP checker project, I’m using Bing Search API 2.0 which means that those codes will no longer working after 1st August.

Windows Azure Datamarket provide a trial package and a free package that has limit for 5000 requests per month. More than enough for us to toying for Bing SERP checker.

Go get your Account Key (was Application ID) :

This is the revised main function php codes so it will work on new Windows Azure Datamarket web service

//this is the main function
function b_serp($keyword, $site, $market, $api_key)
	$site=str_replace(array('http://'), '', $site);
	$context = stream_context_create(array(
		'http' => array(
		    'request_fulluri' => true,
		    'header'  => "Authorization: Basic " . base64_encode($api_key . ":" . $api_key)

	while ((!$found)&&($pos<=100)) {
		//this is the end point of microsoft azure datamarket that we should call  -- only take data from web results
		//I'm using generic file_get_contents because cURL CURLOPT_USERPWD didn't work (no idea why)
		$response=file_get_contents($end_point, 0, $context);
		foreach ($json_data->d->results as $res) {

			if (substr_count(strtolower($theweb['host']), $site))
		                return $ret;

	if (!$found)
		return NULL;

How you call it:

$account_key='put your account key here';
$res=b_serp('how to upload mp3 to youtube', '', 'en-US', $account_key);

Example output:

array(3) {
  string(70) "MP32U.NET - Helping independent artist getting acknowledged in the ..."
  string(21) ""

Fully working demo:

Actually, there are a lot of other “Search Market” that supported by Bing but I only listed some of them just for example. Download this document for complete list of Bing’s supported Search Market:


  1. Your PHP version must be PHP 5.2 or higher (because of json_decode command)
  2. You must activate PHP OpenSSL module (php_openssl) because we are using file_get_contents and the webservice end point must be accessed via HTTPS

Update (2012-07-20) : the endpoint URL is changed

[php] Simple captcha alternative — using math question

Today, I received some task to implement some kind of captcha in some forms in hope that this captcha will reduce the garbage and automated submission. The client asked me to implement some user friendly captcha not those that hard to see. Re-Captcha and image based captcha (such as that I implemented in mp3 to Youtube‘s contact form) is not an option. Finally, the client decided to use captcha that ask visitors some simple math problem, i.e. addition and subtraction.

I remember that one of wordpress plugin had this kind of feature. I think it’s Contact Form 7. Oh, it’s actually Really Simple Captcha plugin. But there’s another huge problem. The website is not even a wordpress-based blog/site, it’s just simple site, probably created from ground-up using Dreamweaver. So, once again, installing a plugin is not an option.

After analyzing the requirements, I decided to create it myself. This is the simple captcha features that I created:

  • it use PHP session
  • the question is just a simple math addition or subtraction. No hard to see words or image
  • the number in the math problem is small (1 – 10), 4th grader would be easily solve the math problem
  • easily added to any existing PHP forms
  • works for PHP (non-CMS) based site.

The main code is saved in file named “scaptcha.php“. This is the full source codes:


	"If you're human, what is",
	"Solve this math problem",
	"To prove you're human, please solve this",
	"What's the result of",
	"Prove that you are human! Solve this"


$sentences_idx=mt_rand(0, count($sentences)-1);  //choose which sentence to show
$_SESSION['sentence']=$sentences[$sentences_idx];  //save it to session
$operands_idx=mt_rand(0, count($operands)-1);  //choose which math operand
$_SESSION['operand']=$operands[$operands_idx];  //save it to session

$num1=mt_rand(1, 10);
$num2=mt_rand(1, 10);

switch ($_SESSION['operand']) {
	case "+":

	case "-":
                //check which one is smaller
                if ($num1<$num2) {
                        //swicth value


First, it will start PHP session. $sentence array is used to store the sentences that will be seen by visitors before the math problem. You can edit it as you wish. $operands array is the math operand supported by this simple captcha script. The script then choose which sentence to be shown and the math operand randomly. Next, it will randomly choose 2 numbers between 1 and 10, operate it mathematically then store the result in PHP session.

The form that want to use this simple captcha have to include the file above (scaptcha.php).


require_once "scaptcha.php";

Then, inside a form HTML element and --usually-- exactly before form Submit button, these codes must be placed:

echo $_SESSION['sentence']." ".$_SESSION['num1']." ".$_SESSION['operand']." ".$_SESSION['num2']." ? ";
echo "";

As you can see, the script simply show the random sentence, both numbers and operand to users then create a new text- type input where user can put it's answer. The input text is named "answer", you can change this if it's already used in different form's element name.

The target file (where the POST variables from the current form is sent and processed) must use session_start()in order to "catch" the "correct answer" of the simple captcha. Then compare the value between the correct answer saved in session and the user/visitor answer. If the answer is the same, then continue processing the form, if not, then show an error messages:


if ($_POST['answer']!=$_SESSION['result']) {
	echo "Your answer is wrong! Are you human?";
} else {
	echo "Your answer is correct!";

You have to match the $_POST['answer'] with the input text form's element name generated by the script inside the previous form (only if you changed it to other names than 'answer').

Full working demo can be tested here:

Simple SOCKS5 proxy checker

OK, found another small project from old blog. I’ve created small PHP script to check whether a SOCKS5 proxy server is alive or not.

Full source code here (can’t write in this post because the source code is mixed with HTML codes):

Fully working demo URL:

simple socks5 checker result

Where to get SOCKS5 proxy list for FREE?

Remember that the script is only working for SOCKS version 5, not 4