Map Koordinat GPS Visual C#

map

map_gui

Source static map yang digunakan adalah dari openstreetmap karena free. Bisa juga menggunakan google map Static Maps API V2 Developer akan tetapi 25 000 free static map requests per application per 24 hour period. Lebih dari itu harus mempunyai API_KEY  Google Maps API for Business.

Item yang digunakan pada contoh ini menggunakan picturebox1 untuk menampilkan map yang di browsing lewat koneksi internet, timer1 memberi jeda waktu untuk merefresh map, dan label1 untuk menampilkan parameter yang ingin dipantau (fleksible untuk memudahkan memeriksa parameter2). Karena input latitude dan longitude yang saya berikan adalah dengan format yang terdapat pada SiRF NMEA Reference Manual hardware GPS, dengan format Latitude ddmm.mmmm,N/S Indicator, Longitude dddmm.mmmm, N/S Indicator, maka saya melakukan konversi dahulu kedalam desimal.

 
Decimal Degrees = Degrees + minutes/60 + seconds/3600

 

public double conversi_degrees(double time_deg)
{
   double depan = (double)(int)time_deg;
   double belakang = time_deg - depan;
   double degrees = (double)(int)(depan/100);
   double minutes = Math.Round(time_deg - (degrees*100),6);
   double dec_degrees = degrees + Math.Round((minutes/60),6);
   return (dec_degrees);
}

 
Setelah didapat nilai dalam format desimal, maka variabel tersebut siap dimasukan ke dalam format URL dari openstreetmap untuk kemudian ditampilkan di picturebox1.
kode lengkap.
 

using System;
using System.Windows.Forms;

namespace GPS_MAP
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        int jum_pin = 5;
        double center_lat_val = -658.62665;
        double center_long_val = 10737.81812;
        double[] center_lat_pin = new double[5] { -658.62665, -658.62665, -658.62665, -658.62665, -658.62665 };
        double[] center_long_pin = new double[5] { 10737.81812, 10737.92722, 10738.03632, 10738.14542, 10738.25442 };
        
        string url_data;
        string pin_data;

        int count = 15;
        private void timer1_Tick(object sender, EventArgs e)
        {
            double lat_val;
            double long_val;
            lat_val = conversi_degrees(center_lat_val);
            long_val = conversi_degrees(center_long_val);
            int val_zoom = count;
            pin_data = "";
            for (int i = 0; i < jum_pin; i++)
            {
                double lat_pin = conversi_degrees(center_lat_pin[i]);
                double long_pin = conversi_degrees(center_long_pin[i]); 
                pin_data += string.Format("{0},{1},lightblue{2}|", lat_pin, long_pin,i+1);
            }
            url_data = String.Format("http://staticmap.openstreetmap.de/staticmap.php?center={0},{1}&zoom={2}&size=600x300&maptype=mapnik&markers={3}",lat_val,long_val,val_zoom,pin_data);
            pictureBox1.ImageLocation = url_data;

            label1.Text = url_data;
        }

        public double conversi_degrees(double time_deg)
        {
            double depan = (double)(int)time_deg;
            double belakang = time_deg - depan;
            double degrees = (double)(int)(depan/100);
            double minutes = Math.Round(time_deg - (degrees*100),6);
            double dec_degrees = degrees + Math.Round((minutes/60),6);
            return (dec_degrees);
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            timer1.Enabled = true;
        }

        protected override void OnMouseWheel(MouseEventArgs mea)
        {
            if (mouse_stat_enter == 1)
            {
                count += mea.Delta / 120;
                if (count < 0)
                    count = 0;
                else if (count > 18)
                    count = 18;
            }
        }

        int mouse_pos_X, mouse_pos_Y;
        int prev_mouse_pos_X, prev_mouse_pos_Y;
        private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
        {
            pictureBox1.Cursor = Cursors.Hand;
            prev_mouse_pos_X = e.X;
            prev_mouse_pos_Y = e.Y; 
        }

        private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
        {
            pictureBox1.Cursor = Cursors.Default;
            mouse_pos_X = e.X;
            mouse_pos_Y = e.Y;
            int delta_X = prev_mouse_pos_X - mouse_pos_X;
            int delta_Y = prev_mouse_pos_Y - mouse_pos_Y;
            double constanta;
            if((count >=15)&&(count<=18))
                constanta = 20;
            else if((count >=12)&&(count<15))
                constanta = 8;
            else if((count >=9)&&(count<12))
                constanta = 1;
            else if((count >=6)&&(count<9))
                constanta = 0.5;
            else if((count >=3)&&(count<6))
                constanta = 0.1;
            else
                constanta = 0.1;
            center_lat_val -= (double)delta_Y/(count*constanta);
            center_long_val += (double)delta_X/(count * constanta);
        }

        int mouse_stat_enter = 0;
        private void pictureBox1_MouseEnter(object sender, EventArgs e)
        {
            mouse_stat_enter = 1;
        }

        private void pictureBox1_MouseLeave(object sender, EventArgs e)
        {
            mouse_stat_enter = 0;
        }
    }
}

 
________________________________________
Daftar Pustaka
wiki.openstreetmap.org/wiki/Static_map_images
staticmap.openstreetmap.de/
developers.google.com/maps/documentation/staticmaps/
itouchmap.com/latlong.html
andrew.hedges.name/experiments/convert_lat_long/

One Response to Map Koordinat GPS Visual C#

  1. Terima kasih atas sarannya

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s