1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
/***************************************************************************
* search_coordinate.c
*
* Copyright 2005 Ian McIntosh
* ian_mcintosh@linuxadvocate.org
****************************************************************************/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Library General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <gtk/gtk.h>
#include <math.h>
#include <stdlib.h>
#include "main.h"
#include "map.h"
#include "util.h"
#include "search_coordinate.h"
#include "glyph.h"
#include "searchwindow.h" // for defines about glyph size
#define COORDINATE_RESULT_SUGGESTED_ZOOMLEVEL (37) // no idea what to use for this :)
#define FORMAT_COORDINATE_RESULT ("<b>Lat:</b> %10.5f\n<b>Lon:</b> %10.5f")
static void search_coordinate_add_result(const mappoint_t* pPoint);
//
// globals
//
static glyph_t* g_SearchResultTypeCoordinateGlyph = NULL;
//
// Public API
//
void search_coordinate_init()
{
g_SearchResultTypeCoordinateGlyph = glyph_load_at_size("search-result-type-coordinate", SEARCHWINDOW_SEARCH_RESULT_GLYPH_WIDTH, SEARCHWINDOW_SEARCH_RESULT_GLYPH_HEIGHT);
}
void search_coordinate_execute(const gchar* pszSentence)
{
//mappoint_t ptResult = {0};
// Goals:
// Make sure never to match something that could likely be a road or POI search!
// That said, be _as flexible as possible_ with input formats.
// Here are some examples from the web:
// 32° 57' N 85° 57' W
// 37 degrees N 123 degrees W
// 40 02 40
// 43° 28' 07" N
// 49:30.0-123:30.0
// 49.5000-123.5000
// h&lat=32.11611&lon=-110.94109&alt=
// And our own:
// Lat: 1.0, Lon: -1.0
// And of course, don't match things out of valid range (map.h has constants: MIN_LATITUDE, MAX_LATITUDE, MIN_LONGITUDE, MAX_LONGITUDE)
// Call only if we have a likely match!
//search_coordinate_add_result(&ptResult);
}
//
// Private
//
static void search_coordinate_add_result(const mappoint_t* pPoint)
{
gchar* pszBuffer = g_strdup_printf(FORMAT_COORDINATE_RESULT, pPoint->fLatitude, pPoint->fLongitude);
searchwindow_add_result(SEARCH_RESULT_TYPE_COORDINATE, pszBuffer, g_SearchResultTypeCoordinateGlyph, pPoint, COORDINATE_RESULT_SUGGESTED_ZOOMLEVEL);
g_free(pszBuffer);
}
|