Skip to main content

Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "EclipseLink/Examples/MOXy/JSON Geocode"

Line 4: Line 4:
  
 
This example will demonstrate mapping a single object model to both XML and JSON using the same set of metadata.  Google Maps Geocoding API V2 will be used to provide the XML and JSON inputs for this example.
 
This example will demonstrate mapping a single object model to both XML and JSON using the same set of metadata.  Google Maps Geocoding API V2 will be used to provide the XML and JSON inputs for this example.
 +
  
 
==XML Input==
 
==XML Input==
Line 10: Line 11:
  
 
http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=xml&sensor=false&key=YOUR_KEY_HERE
 
http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=xml&sensor=false&key=YOUR_KEY_HERE
 +
  
 
==XML Result==
 
==XML Result==
Line 59: Line 61:
 
</source>
 
</source>
 
</div>
 
</div>
 +
  
 
==JSON Input==
 
==JSON Input==
 
JSON Input
 
  
 
Below is the link we will use to get the data as JSON.  This is specified in the output parameter.  Note the '''output=json''' in the URL:
 
Below is the link we will use to get the data as JSON.  This is specified in the output parameter.  Note the '''output=json''' in the URL:
  
 
http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=json&sensor=false&key=YOUR_KEY_HERE
 
http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=json&sensor=false&key=YOUR_KEY_HERE
 +
 +
 +
==JSON Result==
 +
 +
<div style="width:850px">
 +
<source lang="text">
 +
Below is an example of the XML returned from Google Maps:
 +
 +
{
 +
  "name": "1600 Amphitheatre Parkway, Mountain View, CA",
 +
  "Status": {
 +
    "code": 200,
 +
    "request": "geocode"
 +
  },
 +
  "Placemark": [ {
 +
    "id": "p1",
 +
    "address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
 +
    "AddressDetails": {
 +
  "Accuracy" : 8,
 +
  "Country" : {
 +
      "AdministrativeArea" : {
 +
        "AdministrativeAreaName" : "CA",
 +
        "Locality" : {
 +
            "LocalityName" : "Mountain View",
 +
            "PostalCode" : {
 +
              "PostalCodeNumber" : "94043"
 +
            },
 +
            "Thoroughfare" : {
 +
              "ThoroughfareName" : "1600 Amphitheatre Pkwy"
 +
            }
 +
        }
 +
      },
 +
      "CountryName" : "USA",
 +
      "CountryNameCode" : "US"
 +
  }
 +
},
 +
    "ExtendedData": {
 +
      "LatLonBox": {
 +
        "north": 37.4227454,
 +
        "south": 37.4200474,
 +
        "east": -122.0843863,
 +
        "west": -122.0870843
 +
      }
 +
    },
 +
    "Point": {
 +
      "coordinates": [ -122.0857353, 37.4213964, 0 ]
 +
    }
 +
  } ]
 +
}
 +
</source>
 +
</div>

Revision as of 12:48, 18 June 2012

JSON Binding: Google Geocode Example

This example will demonstrate mapping a single object model to both XML and JSON using the same set of metadata. Google Maps Geocoding API V2 will be used to provide the XML and JSON inputs for this example.


XML Input

Below is the link we will use to get the data as XML. This is specified in the output parameter. Note the output=xml in the URL:

http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=xml&sensor=false&key=YOUR_KEY_HERE


XML Result

Below is an example of the XML returned from Google Maps:

<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0">
 <Response>
  <name>1600 Amphitheatre Parkway, Mountain View, CA</name>
  <Status>
   <code>200</code>
   <request>geocode</request>
  </Status>
  <Placemark id="p1">
   <address>1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA
   </address>
   <AddressDetails Accuracy="8"
    xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0">
    <Country>
     <CountryNameCode>US</CountryNameCode>
     <CountryName>USA</CountryName>
     <AdministrativeArea>
      <AdministrativeAreaName>CA</AdministrativeAreaName>
      <Locality>
       <LocalityName>Mountain View</LocalityName>
       <Thoroughfare>
        <ThoroughfareName>1600 Amphitheatre Pkwy</ThoroughfareName>
       </Thoroughfare>
       <PostalCode>
        <PostalCodeNumber>94043</PostalCodeNumber>
       </PostalCode>
      </Locality>
     </AdministrativeArea>
    </Country>
   </AddressDetails>
   <ExtendedData>
    <LatLonBox north="37.4227454" south="37.4200474" east="-122.0843863"
     west="-122.0870843" />
   </ExtendedData>
   <Point>
    <coordinates>-122.0857353,37.4213964,0</coordinates>
   </Point>
  </Placemark>
 </Response>
</kml>


JSON Input

Below is the link we will use to get the data as JSON. This is specified in the output parameter. Note the output=json in the URL:

http://maps.google.com/maps/geo?q=1600+Amphitheatre+Parkway,+Mountain+View,+CA&output=json&sensor=false&key=YOUR_KEY_HERE


JSON Result

Below is an example of the XML returned from Google Maps:
 
{
  "name": "1600 Amphitheatre Parkway, Mountain View, CA",
  "Status": {
    "code": 200,
    "request": "geocode"
  },
  "Placemark": [ {
    "id": "p1",
    "address": "1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA",
    "AddressDetails": {
   "Accuracy" : 8,
   "Country" : {
      "AdministrativeArea" : {
         "AdministrativeAreaName" : "CA",
         "Locality" : {
            "LocalityName" : "Mountain View",
            "PostalCode" : {
               "PostalCodeNumber" : "94043"
            },
            "Thoroughfare" : {
               "ThoroughfareName" : "1600 Amphitheatre Pkwy"
            }
         }
      },
      "CountryName" : "USA",
      "CountryNameCode" : "US"
   }
},
    "ExtendedData": {
      "LatLonBox": {
        "north": 37.4227454,
        "south": 37.4200474,
        "east": -122.0843863,
        "west": -122.0870843
      }
    },
    "Point": {
      "coordinates": [ -122.0857353, 37.4213964, 0 ]
    }
  } ]
}

Copyright © Eclipse Foundation, Inc. All Rights Reserved.