[NUUG fiksgatami] [patch] Use mapit for post code locations also for fiksgatami

Petter Reinholdtsen pere at hungry.com
Sat Mar 5 13:05:56 CET 2011


Here is the fixmystreet part of the patch to use mapit as the postcode
coordinate source for www.fiksgatami.no.

I'm not sure if this is correct, as the string representation of
lat/long can end up with the wrong decimal point.  Perhaps better to
use sprintf("%f", $var) in the correct locale to avoid the implicit
string conversion?

Anyway, here is the first draft, currently being tested on
fiksgatami-dev.nuug.no.

Happy hacking,
-- 
Petter Reinholdtsen
-------------- next part --------------
diff --git a/commonlib b/commonlib
index 5d1916f..f8bd47e 160000
--- a/commonlib
+++ b/commonlib
@@ -1 +1 @@
-Subproject commit 5d1916f6e20aec35d6799d9228b828520fcbfeea
+Subproject commit f8bd47ec427fd45047f937fe09155a530045eef7
diff --git a/perllib/FixMyStreet/Geocode.pm b/perllib/FixMyStreet/Geocode.pm
index 02cdf21..4f1a57f 100644
--- a/perllib/FixMyStreet/Geocode.pm
+++ b/perllib/FixMyStreet/Geocode.pm
@@ -50,6 +50,17 @@ sub lookup {
                 $longitude = $location->{wgs84_lon};
             }
         }
+    } elsif (mySociety::Config::get('COUNTRY') eq 'NO') {
+        #if (mySociety::PostcodeUtil::is_valid_postcode($s)) {
+        if ($s =~ /^\d{4}$/) {
+            my $location = mySociety::Locale::in_gb_locale {
+                mySociety::MaPit::call('postcode', $s);
+            };
+            unless ($error = Page::mapit_check_error($location)) {
+                $latitude  = $location->{wgs84_lat};
+                $longitude = $location->{wgs84_lon};
+            }
+        }
     }
     unless ($error || defined $latitude) {
         ($latitude, $longitude, $error) = FixMyStreet::Geocode::string($s, $q);
diff --git a/perllib/FixMyStreet/Map/OSM.pm b/perllib/FixMyStreet/Map/OSM.pm
index fb3770d..9b3fe70 100644
--- a/perllib/FixMyStreet/Map/OSM.pm
+++ b/perllib/FixMyStreet/Map/OSM.pm
@@ -11,6 +11,7 @@ package FixMyStreet::Map;
 use strict;
 use Math::Trig;
 use mySociety::Web qw(ent);
+use mySociety::Locale;
 use Utils;
 
 sub header_js {
@@ -64,10 +65,16 @@ sub display_map {
     my $out = FixMyStreet::Map::header($q, $params{type});
     my $copyright = _('Map &copy; <a id="osm_link" href="http://www.openstreetmap.org/">OpenStreetMap</a> and contributors, <a href="http://creativecommons.org/licenses/by-sa/2.0/">CC-BY-SA</a>');
     my $compass = compass($q, $x_tile, $y_tile, $zoom);
+    # Print in gb locale, to try to ensure that the float values
+    # get period (.) as decimal point, and not comma (,).  This 
+    # only work if nothing already convereded the float to a string in
+    # the nb_NO locale.
+    mySociety::Locale::in_gb_locale {
+        $out .= "<input type=\"hidden\" name=\"latitude\" id=\"fixmystreet.latitude\" value=\"$params{latitude}\">\n";
+        $out .= "<input type=\"hidden\" name=\"longitude\" id=\"fixmystreet.longitude\" value=\"$params{longitude}\">\n";
+        $out .= "<input type=\"hidden\" name=\"zoom\" value=\"$zoom\">\n";
+    };
     $out .= <<EOF;
-<input type="hidden" name="latitude" id="fixmystreet.latitude" value="$params{latitude}">
-<input type="hidden" name="longitude" id="fixmystreet.longitude" value="$params{longitude}">
-<input type="hidden" name="zoom" value="$zoom">
 <script type="text/javascript">
 var fixmystreet = {
     'latitude': $params{latitude},
diff --git a/templates/website/cobrands/fiksgatami/faq-nb b/templates/website/cobrands/fiksgatami/faq-nb
index b4673d6..e702a5f 100644
--- a/templates/website/cobrands/fiksgatami/faq-nb
+++ b/templates/website/cobrands/fiksgatami/faq-nb
@@ -72,14 +72,13 @@
   vi anser ?? v??re upassende fortrinnsvis etter ?? bli informert av en
   bruker p?? nettstedet.</dd>
 
-  <dt>Hvorfor blir ikke mitt postnummer / stedsnavn funnet?</dt>
+  <dt>Hvorfor blir ikke mitt stedsnavn funnet?</dt>
 
   <dd>Tjenesten bruker navnes??k hos Google Maps for ?? lokalisere
-    postnummer og steder.  Hvis Google Maps har mangler i sin
-    postnummer og stedsnavndatabase, vil stedet ikke bli funnet eller
-    sende deg til feil plass.  Tilsvarende s??k hos Google (etter
-    f.eks. "1234, Norway") vil ogs?? feile.  For ?? fikse det m?? en ta
-    kontakt med Google.</dd>
+    steder.  Hvis Google Maps har mangler i sin stedsnavndatabase, vil
+    stedet ikke bli funnet eller sende deg til feil plass.
+    Tilsvarende s??k p?? Google Maps (etter f.eks. "Slogv??r, Norway")
+    vil ogs?? feile.  For ?? fikse det m?? en ta kontakt med Google.</dd>
 
 </dl>
 


More information about the fiksgatami mailing list