Making a request to google by javaScript -


i've following code in java script:

var requestdata =                 {                     "homemobilecountrycode": 732,                     "homemobilenetworkcode": 123,                     "radiotype": "gsm",                     "carrier": "vodafone",                     "celltowers":                     [                         {                             "cellid": 21282,                             "locationareacode": 2110,                             "mobilecountrycode": 732,                             "mobilenetworkcode": 123,                             "age": 0,                             "signalstrength": (57 - 110)                         }                     ]                 } var encoded = $.tojson(requestdata); $.ajax({                 url: "https://www.googleapis.com/geolocation/v1/geolocate?key=aizasya8ujk3m8_x_6gv3t5ewhc86giumhitu34",                 type: "post",                 contenttype: "application/json; charset=utf-8",                 datatype: 'json',                 data: encoded,                 success: function (response) {                     var location = response.location;                     var lat = location.latitude;                     var lon = location.longitude;                     var address = location.address.street_number + " " + location.address.street + " " + location.address.city + " " + location.address.county + " " + location.address.country;                                 },                 error: function (er) {                     alert("error " + er.message + " codigo: " + er.code);                 }             }); 

the request doesn't return me nothing , on alert error: apears object undefined, so, have of example of invocation service google using json ?? i'm working on asp.net enter image description here


hi don't have experience making kind of request, have follow code:

tower tower = new tower();          tower.mobilecountrycode = "310";         tower.mobilenetworkcode = "260";         tower.cellstowers = new list<celltower>();         tower.cellstowers.add(new celltower()         {             cellid = "39627456",             locationareacode = "40495",             mobilecountrycode = "310",             mobilenetworkcode = "260",             signalstrength = "-95",             age = "0"         });          string jsonformat = tojson(tower);          webrequest request = webrequest.create("https://www.googleapis.com/geolocation/v1/geolocate?key=aizasya8ujk3m8_x_6gv3t5ewhc86giumhitu34" + jsonformat); 

and have thw follow function:

string tojson(object obj)     {         javascriptserializer serializer = new javascriptserializer();         return serializer.serialize(obj);     } 

but service response with: error 400, invalid request ...

any idea ??

you trying use google maps geolocation api javascript. json api. meant use server, not javascript code.

the api returns json result, , can't cross-domain request javascript unless api allows via cors or provides jsonp response. unless i'm mistaken, api neither of those, can't use javascript.

if want geocoding javascript, can use geocoding service in maps api. don't think supports radio tower stuff you're using though - @ least documentation doesn't mention it.

also, posted api key in question. if browser api key, that's no problem, if server api key of sort use geolocation api, key compromised. go api console, delete key, , create new 1 - , don't share new key!


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -