在给定的lat中获取位置,在ajax中获取long

时间:2013-03-22 06:35:59

标签: javascript jquery ajax

我很难找到lat,long和radius中使用ajax或javascript的地方,我使用ajax代码来找到这个但是得到错误, 我的代码是:

   $.ajax({ url: 'https://maps.googleapis.com/maps/api/place/nearbysearch/json?',
      data: {
        location:'-33.8670522,151.1957362',
        radius:500,
       sensor:false,
      key:'AIzaSyAImBQiqvaXOQtqeK8VC-9I96kMmB6Mz7I'},
     dataType: "json",
     type: "GET", //or POST if you want => update your php in that case
      success: function( data ) {
     for(var i in data.results){
       alert(data.results[i]);
     }
    },
    error: function (request, status, error) {
     alert("error");
    //handle errors
   }
    });

它得到结果错误,请帮我找到这个

由于

1 个答案:

答案 0 :(得分:0)

尝试使用以下代码从位置附近获取地点

function initialize(arg)
    {        


        directionsDisplay = new google.maps.DirectionsRenderer();
        mapmarker="img/pois/"+arg+".png";
        geocoder = new google.maps.Geocoder();

        var location = new google.maps.LatLng(11.21989,78.16811099999995);
          map = new google.maps.Map(document.getElementById('googleMap'), {
              mapTypeId: google.maps.MapTypeId.ROADMAP,
              center: location,
              zoom: 15
            });

          directionsDisplay.setMap(map);


          var request = {
            location: location,
            radius: '5000',
            types: [arg]
          };
          infowindow = new google.maps.InfoWindow();
          var service = new google.maps.places.PlacesService(map);
          service.nearbySearch(request, callback);

    }


    //google.maps.event.addDomListener(window, 'load', initialize);
    function callback(results, status) 
    {
          if (status == google.maps.places.PlacesServiceStatus.OK)
          {
        for (var i = 0; i < results.length; i++)
        {
          var place = results[i];
          createMarker(results[i]);


        }
          }
    }