Ignore:
Timestamp:
Feb 7, 2007, 4:08:30 PM (13 years ago)
Author:
Nick Burch
Message:

Pull out e+n -> lat+long into a npemap perl module, and use from the geocoder

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/npemap.org.uk/cgi/geocoder.fcgi

    r460 r461  
    2323use lib "$FindBin::Bin/../perllib";
    2424use NPEMap;
    25 use Geo::HelmertTransform;
     25use NPEMap::GeoConverter;
    2626
    2727sub print_err;
     
    185185        }
    186186
     187        # Generate the lat and long, if we had easting and northings
     188        foreach my $res (@results) {
     189                if($res->{easting} && $res->{northing}) {
     190                        ($res->{lat},$res->{long}) =
     191                                eastingNorthingToLatLong($res->{easting},$res->{northing});
     192                }       
     193        }
    187194
    188195        # Render
     
    209216                        print "    <northing>".$res->{inorthing}."</northing>\n";
    210217                        print "    <postcode>$res->{postcode}</postcode>\n";
     218                        print "     <latitude>$res->{lat}</latitude>\n";
     219                        print "     <longitude>$res->{long}</longitude>\n";
    211220                        if(scalar @results > 1) {
    212221                                print "  </result>\n";
     
    225234                #  (need to do some array magic probably)
    226235                foreach my $res (@results) {
    227                         print "{ pc: \"$res->{postcode}\", e: $res->{ieasting}, n: $res->{inorthing} }";
     236                        print "{ \"pc\": \"$res->{postcode}\", \"e\": $res->{ieasting}, \"n\": $res->{inorthing}, \"lat\": $res->{lat}, \"lng\": $res->{long} }";
    228237                }
    229238                if(defined $cgi->param("callback")) {
     
    233242    } else {
    234243                print header("text/plain");
    235                 print "# Easting,Northing,Matched Postcode\n";
     244                print "# Easting,Northing,Matched Postcode,Latitude,Longitude\n";
    236245
    237246                foreach my $res (@results) {
    238                         print $res->{ieasting}.",".$res->{inorthing}.",'".$res->{postcode}."'\n";
     247                        print $res->{ieasting}.",".$res->{inorthing}.",'".$res->{postcode}."',".$res->{lat}.",".$res->{long}."\n";
    239248                }
    240249        }
Note: See TracChangeset for help on using the changeset viewer.