Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6471119
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:11:17+00:00 2026-05-25T06:11:17+00:00

I am new to handling JSON data and I am trying to learn it

  • 0

I am new to handling JSON data and I am trying to learn it by getting data from the Police API and displaying it on my Google Map.

Basically I want to take in a user input which gets Geocoded and then does a request to “http://policeapi2.rkh.co.uk/api/crimes-street/all-crime?lat=52.629729&lng=-1.131592” (lat and long being the geocoded address).

I have been searching all over, but anything that seems to use cURL (which is what they suggest on their website), gets involved with PHP. There was a good example on richardalan.co.uk, but I have never used PHP in my life and the technologies I am using are Spring MVC, Google App Engine, Google Maps(JavaScript).

I just want to know if I can do it in my JavaScript that has also been used to create functions for my maps and how do I do it?

Thank you in advanced,

Mark

I have now provided this question with a solution

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T06:11:18+00:00Added an answer on May 25, 2026 at 6:11 am

    I have done this now using my Spring MVC controllers to GET the JSON data I needed and then displayed it in my page and on a Google Map using JQuery AJAX.

    Here is my Controller that gets the JSON data from the Police API:

        @Controller
    public class CrimeRESTController {
    
    
        @RequestMapping(value = "/crimes", method = RequestMethod.GET)
        public @ResponseBody Object jsonCrimes(){
    
                SimpleClientHttpRequestFactory s = new SimpleClientHttpRequestFactory() {
                @Override
                protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
                    super.prepareConnection(connection, httpMethod);
    
                    //Basic Authentication for Police API
                    String authorisation = "username" + ":" + "password";
                    byte[] encodedAuthorisation = Base64.encode(authorisation.getBytes());
                    connection.setRequestProperty("Authorization", "Basic " + new String(encodedAuthorisation));
                }
            };
    
    
            RestTemplate rt = new RestTemplate(s);
    
    
            Object crime;
            crime = rt.getForObject("http://policeapi2.rkh.co.uk/api/crimes-street/all-crime?lat=53.4107766&lng=-2.9778383", Object.class);
    
            return crime;
    
        }
    }
    

    Here is part of my index.jsp page where I display the JSON data onto the map:

        <script>                
               <%---------------------------------------------------%>
               <%---------CODE THE LAT LONG IN INPUT FIELD----------%>
               <%---------------------------------------------------%>
               function codeLatLng(latitude, longitude){
    
                   var latlng = new google.maps.LatLng(latitude, longitude);
    
                             marker = new google.maps.Marker({
                                 position: latlng,
                                 map: map
                             });
               }
               <%---------------------------------------------------%>
        </script>
    

    Here is part of my index.jsp page where I loop through the JSON data to display the results to my view and also get the longitude and latitude and send it to my function shown above (I understand this might look messy and there might be a better way to do it, but it works):

    <script type="text/javascript">
                function displayCrimesOnMap() {
                    $.getJSON("crimes.htm", function(data) {
                       $('#crimes').text('');
                       $.each(data, function(key, value) {
                           $('#crimes').append('<br>');
                           $.each(value, function(newKey, newValue){
                               if(newKey == "location"){
                                   var latitude;
                                    var longitude;
                                   $.each(newValue, function(key2, value2){
                                    if(key2 == "latitude"){
    
                                        latitude = value2;
                                    }
                                    if(key2 == "longitude"){
    
                                        longitude = value2;
                                    }
                                    if(key2 == "street"){
                                       $('#crimes').append('<p class="areatext">' + '<b>'+key2+'</b>' + '</p>');
                                          $.each(value2, function(key3, value3){
                                               $('#crimes').append('<p class="areatext">' + '<b>'+key3+'</b>' +": " + value3 + '</p>');
                                          })
                                    }else{
                                        $('#crimes').append('<p class="areatext">' + '<b>'+key2+'</b>' +": " + value2 + '</p>');
                                    }
    
                                   })
                                   //alert(latitude+", "+longitude);
                                   codeLatLng(latitude,longitude);
                               }else{
                                    $('#crimes').append('<p class="areatext">' + '<b>'+newKey+'</b>' +": " + newValue + '</p>');
                               }
                           })
                        })
                    });
                }
            </script>
    

    Here is part of my index.jsp page where the information gets output to a specific section in index.jsp:

    <h1 class="areatitle">Crimes...   <input type="button" value="Get Crimes" onclick="displayCrimesOnMap()"/></h1>
                           <div id="crimes">
                           <!--Crimes Appears Here-->
                           </div>
    

    I really do hope this helps someone other than me, as I found I had a hard time understanding AJAX, after I finally understood it, it was actually really easy 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to ASP.NET MVC; something I'm having trouble with is getting data from
I'm currently parsing a JSON response from the Google Translate API. I'm able to
when handling data, i always have to write the following: var dataSourceRequest:URLRequest = new
I am trying to use nunits new way of exception handling but I am
I'm working on a new class to wrap XML handling. I want my class
I've found this doc on how to post JSON data using HttpBuilder. I'm new
So I'm using GSON to parse JSON from an API and am stuck as
I'm quite new to JSON handling and I've got myself stuck. My page contains
I know markerClusterer able to handling large amounts markers on google map. By referring
This is not a new topic, but I am curious how everyone is handling

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.