Reputation: 551
I am building a query to a service. I query the service using ajax and get a response in JSON.
I am querying the Google map API service. Reverse Geocoding
Here is a sample query:
http://maps.googleapis.com/maps/api/geocode/json?latlng=40.714224,-73.961452&sensor=false
You can see the query parameters are latlng
, and sensor
.
There is a comma in the latlng
query parameter.
// Some vars
var googleEndpoint = "http://maps.googleapis.com/maps/api/geocode/json";
// Bind handler to form submission
$('#theQuery').submit(function() {
var lat = $("#lat").val();
var _long = $("#long").val();
// Construct Query
$.get(googleEndpoint, { sensor: true, latlong: lat + ',' + _long }, function (data) {
console.log(data);
});
return false;
});
If I run a query, my query looks like this:
http://maps.googleapis.com/maps/api/geocode/json?sensor=true&latlong=44%2C44
You can see the comma is a %2C
. I know this is due to encodeURIComponent
being called on the parameters as jquery builds the query string, but I don't know how to flag that comma so that it won't be encoded. I have tried unescape()
.
I know I am missing something here, any help?
Upvotes: 2
Views: 1496
Reputation: 1
$.ajax({
type: "GET",
url: "https://maps.googleapis.com/maps/api/elevation/json",
contentType: "text/plain; charset=UTF-8",
data:
"path=36.578581,-118.291994&samples=3"
});
My code works fine,hope to help you!
https://maps.googleapis.com/maps/api/elevation/json?path=36.578581,-118.291994|36.23998,-116.83171&samples=3&key=YOUR_API_KEY
Upvotes: 0