Create post-code based service - java

I want to create a United Kingdom(London focused) post code based application. For instance, one of the basic queries would be:
User comes and types their post code, determine the n most nearby objects to the post code they typed in.
I am using noSQL(MongoDB) and I benefit from DB native geo-spatial objects.
How do I link geo-spatial coordinates to UK postcodes?
Is this long-lat to postcode conversion the right approach?
Is there a service available to cover that part?
How do you convert from London post code to latitude and longitude
so that you can measure distance?

The mapping between UK postcodes and latitude/longtitude is accessible online on this site in form of CSV so it should be easily parsed. In case it wouldn't be available latter for any reasons I've mirrored it here.
As for your first three questions, as written in this post you can store entries like case class Zip(code, location) and perform lookup with $near operator on the second field.

Related

Java API OpenWeatherMap

I have started learning Java a while back and looking at doing my first advanced (for me) project. I am wanting to create a program that uses the OpenWeatherMap API to show the weather for a particular city.
User inputs name of city
City stored as variable
Call API using city variable
Store results in two varibles (City & temp)
Display results using System.out.Println(City, Temp)
I have done some reading before starting and I am seeing people saying that storing api results in variables is bad practice? Just checking I am going down the right route before starting?
Below is an example of the API result
{"coord":{"lon":-0.13,"lat":51.51},"weather":[{"id":300,"main":"Drizzle","description":"light intensity drizzle","icon":"09d"}],"base":"stations","main":{"temp":280.32,"pressure":1012,"humidity":81,"temp_min":279.15,"temp_max":281.15},"visibility":10000,"wind":{"speed":4.1,"deg":80},"clouds":{"all":90},"dt":1485789600,"sys":{"type":1,"id":5091,"message":0.0103,"country":"GB","sunrise":1485762037,"sunset":1485794875},"id":2643743,"name":"London","cod":200}
Not sure why storing data in variables is bad practice. The alternative is to chain methods. e.g. instead of this:
String cityResult = callApi(city);
JSON jsonCityResult = JSON.parse(cityResult);
print(jsonCityResult.temp);
it would be:
print(JSON.parse(callApi(city)).temp);
which is difficult to read, difficult to maintain and difficult to work out what went wrong. Was it the api call or the JSON parse?
As long as the code is 'self documenting', i.e. cityResult instead of cr I think that is perfectable acceptable programming.

How do I pass and extract data in googlemaps api in my android app using java?

I am new to android development but familiar with java. I want to send a request (containing coordinates of locations) to google maps api for distance matrix and later calculate the sum of distances for each point. The response from api is either in javascript or xml (i dont really know which one). How do i send the query in java and how do i extract the distances from the response?
Try using seperate classes to send and recieve data through the Google maps API. try using JSON to send aaplication data.
In order to use any thing like this (or that is owned by google etc.. ) You first need to setup a developer account at https://play.google.com/apps/publish/signup/
It does cost 25 dollars but in all honesty it's worth it as you get access to a lot of different things including the google maps api, if you're not interested in spending the $25 I would suggest looking into an alternative mapping api.
If on the other hand you will spend the money they've got some great tutorials laid out in the documentation!
A Google Maps Distance Matrix API request takes the following form:
https://maps.googleapis.com/maps/api/distancematrix/output?parameters
If you need more information, Refer to "Distance Matrix Requests".
https://developers.google.com/maps/documentation/distance-matrix/intro#DistanceMatrixRequests
You can also use the "getDistanceMatrix" that issues a distance matrix request.
https://developers.google.com/maps/documentation/javascript/3.exp/reference#DistanceMatrixService

Easy way to retrieve data from a javascript

At https://www.conzoom.eu/find-dig-selv/?default there is a form to enter an address and a postcode, when you search you get a code; A1, D3, E2 etc defining which segment this address is in.. I have a lot of addresses in an excel sheet of my customers that I would like to look up - is there an easier way than doing this manually?
Selenium might be what you are looking for. It is made to simulate a user on a website, so it can the inputs, read the outputs, and wait for the site to be ready before entering the next address.
The tricky part is about reading the excel sheet, depending on its format. But you can always write a macro to make the input more "readable".
It is not impossible to do this in Javascript if the data can be moved to a format that the Javascript on the page can parse.
This is not best solution, but it is an approach I have taken in the past when the web server can only server static files, no server side processing.
From what your question suggests the data set is this may not be a practical solution, due to its size and complexity.
If the data was something like POSTCODE, LOCATION_CODE and there was a one to one mapping such as all postcodes starting with MK had a LOCATION_CODE of 83 then the data can be serialised into JSON or XML(JSON prefered).
Now when the user enters the postcode on the form the Javascript retrieves the data from the server as a static file and parses the results. Compares the users inputed POSTCODE against the data and returns a corresponding LOCATION_CODE.
This only works for simple data that changes very infrequently. Alternatively you need a server backend that will connect either to your excel spreadsheet (not good practice) or to a central database with the logic running to perform the search. This logic will need something like #Todd Motto suggested Java or any number of technologies such as C#, PHP, perl

Permanent REST web service url with many and long parameters

Since I found it very difficult to explain my problem in the heading I'm going to explain it a little further:
I want to /I'm writing a JAX-RS web service (Jersey/Servlet3.0) and the corresponding JS library for a geographic use case. The input of the web service are two lists (source & target points) of geographic points (latitude, longitude) and each point having a list of parameters. Since there is basically no limit on the number of points I don't know how to combine the URL length limit and the unlimitedness of the parameter list.
Here are the restrictions again:
Easy to share URL (so POST probably wont quite cut it?) for social media sharing and of course easy debugging
An example configuration can be seen here please note that there can be nested sets of parameters (point 1 has parameters of it's own)
Needs to able to be integrated in external website (with bookmarkable url)
Not all of the parameters are mandatory, what is the best way to deal with defaults/missing values?
What I thought of so far is:
create a boatload of parameters
jsonify the configuration and send it to server via url parameter
But I don't really like these options. Am I missing something?
Sorry for this rather vague question.
Daniel
Ok to your points
for easy sharing why not just implement a tinyURl or bit.ly style sharing system - obviously you can't have both an easy to pass-in url (a URL that makes it easy to give the server detailed information) that is easy to share (human friendly and short) - but you could very easily save the results (or inputs and calculate each time) to a database and link that to a tinyURl.
as an aside POST will be the only way to handle this due to the amount of data.
Just pass as JSON - easy to nest paramaeters that way
Don't quite get this part - for an external site to use this they could post the data and you return the answers - or using point 1 method of 'tinyurl / bit.ly style system it could call this in an iframe?
You would deal with missing parameters / defaults at server side - create a function for each parameter - if parameter is expected then throw error - if parameter has a default include this in your function and if parameter is not included then don't run the function.
Hope that makes sense?

API to calculate which addresses out of an address list are in the radius of another address

What I am trying to do is the following:
I have an address XYZ
I have a list of other Addresses
I want to get out of the list, all the addresses within a certain distance of XYZ
Is it possible, if yes, which API would you recommend to do this? I would like to do this in a Java web-application that I am building using Spring.
I saw that with Google Places API, I would need to give the longitude and latitude of the place as well as the radius and a name of place I am looking for. Is this the common way to do this?
I can't do this with a list containing thousands of addresses since it would be too time consuming.
Would it be better to insert the longitude and latitude in the database at the time I am inserting an address (after verifying it with Google API and getting those information from there), then extracting the addresses within the proper radius directly in the SQL request?
I also found from this post: How to convert an address to a latitude/longitude?
That "use of the geocoder for any purpose other than obtaining locations that will be displayed using the Google Maps APIs is a violation of the Terms of Service."
So let's say that, if I build a website that will help people find "pizza places" near buy an address they input, then I display a list of these places on the website, it is illegal?

Categories

Resources