javascript - Google's Places API and JQuery request - Origin http://localhost is not allowed by Access-Control-Allow-Origin -
i doing testing project got in mind involves using places nearby. went big guy , started messing around google's places api. i'm using leaflet openstreet tiles map. fine until try use dang thing.
var lat = coords.lat; var lng = coords.lng; var apiurl = "https://maps.googleapis.com/maps/api/place/nearbysearch/json"; var data = { key: 'aizasybl8bme8kqt7rjoxhp6k2ydti44h9-fsui', location: lat+','+lng, radius: '10000', sensor: 'false', rankby: 'prominence', types: 'bar|night_club' }; $.ajax({ url: apiurl, type: 'post', data: data, datatype:"jsonp", crossdomain: true, success: function(data) { var obj = $.parsejson(data); // console.log(data.next_page_token); } }); changing datatype property json origin http://localhost not allowed access-control-allow-origin. using jsonp parsing error unexpected token : obviusly $.parsejson not work... there way make work without having use google maps api? if answer no... there places api google's?
thanks!
you're trying use places api web service, meant use server code , not support jsonp output you'd need javascript.
in javascript, need use places library maps api v3. can't hit url directly javascript or jquery code. (you could discover url pattern places library uses, terms of service don't allow direct use without going through api/library, , url change @ time.)
is there reason don't want use maps api javascript?
Comments
Post a Comment