Hi,
I'm currently working on a project that requires the use of geolocation which access a database of over 200,000 records. I need to retrieve the city from the lat/long location. Is it possible, from BC to access this database in Javascript or other method. What would be the best way do this?
Michel Adey
Hey there, your not the first to ask about this.
In what form is the data? If it is in xml or JSON format or has an option for that you can.
You have BC system tags to return the persons IP and also country code to be used in this regard as well.
The in's and out's of course are all dependant on the exact needs and what you are doing.
Hi Liam,
That was my question:) what would be the best way to access a 200 000 records database. My Javascript code actually retrieve the geolocation of the browser, take de Lat/Long and find the neerest postal in a mySQL table containing postalCode,lat,long,city. XML is slow as I know it! A web service? or is there any technology that can retrieve data faster in BC from a large database?
MIchel Adey
XML and JSON are just data formats, they are neither slow or fast.
Also JavaScript running in a web browser does not have the abililty to direclty connect to a MySql database.
Here is a high level overview of what needs to happen in order to do what you are asking:
-Write javascript that talks to a web service.
-The web service will query the database for the information you want (in your case the postal code that coresponds to the lat/long you provide).
-The web service will take the data from the database and format it as XML or JSON, and the webservice will return that to the browser, where your javascript will pick it up, parse it, display it, or do whatever you need to do with it.
Also, since the webservice can't be hosted on your site (BC doesn't have any way to do that), it will have to be on another domain and hosted seperately from your primary site. Something like webservice.example.com instead of www.example.com. However because of this, the browsers built-in security system will take over, and not allow the data from the external service to be consumed. To get around this limitation you will need to configure your webserivce to send data as JSONP, or use CORS, which is unfortunately not supported in some older browsers.
There are lots of differently ways to create and host a webservice.
However, I'd first look for a pre-built service that does what you want.
North America
Europe, Middle East and Africa
Asia Pacific