Skip navigation
Currently Being Moderated

Database access

May 11, 2012 9:30 AM

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

 
Replies
  • Liam Dilley
    3,997 posts
    Feb 28, 2012
    Currently Being Moderated
    May 12, 2012 4:23 AM   in reply to M. 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.

     
    |
    Mark as:
  • Currently Being Moderated
    May 17, 2012 4:07 PM   in reply to M. 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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points