SANR1103219
SANR1103219

Reputation: 143

how to get phone number using google api

this is my code

function show(placelanlat,names) 
{   
var placenames=names;
var planlat=placelanlat;
var newStr= planlat.replace(/[(\)]/g,'');
var aCars = newStr.split(',');
var infowindow = new google.maps.InfoWindow();
var marker;
var geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(12.588,-83.667);
var myOptions = {
  zoom: 8,
  center: latlng,
  mapTypeId: google.maps.MapTypeId.ROADMAP
}
var map = new google.maps.Map(document.getElementById("map_canvass"), myOptions);
var input = newStr;
var latlngStr = input.split(",",2);
var lat = parseFloat(latlngStr[0]);
var lng = parseFloat(latlngStr[1]);
var latlng = new google.maps.LatLng(lat, lng);
geocoder.geocode({'latLng': latlng}, function(results, status) {  
if (status == google.maps.GeocoderStatus.OK) {
  if (results[1]) {
    map.setZoom(11);
    marker = new google.maps.Marker({
      position: latlng,
      map: map,
      icon: 'images/images.png'
    });
    infowindow.setContent(placenames+"</br>"+results[0].formatted_address+"</br>");
    infowindow.open(map, marker);
    }
    }
  else {
  alert("Geocoder failed due to: " + status);
  }
   });
 return false; // MANDATORY!
  } 

if i set

infowindow.setContent(placenames+"</br>"
                      +results[0].formatted_address
                      +"</br>"+results[0].formatted_phone);
results[0].formatted_phone ->

this is showing empty.why? where i want to change to get place phone number. example:http://www.google.com/maps?source=uds&daddr=India,++%28India%[email protected],78.96288&saddr=37.781287,-122.395575

Upvotes: 4

Views: 11938

Answers (1)

xkeshav
xkeshav

Reputation: 54016

if you use The Google Places API (Experimental) then follow these steps

Certain parameters are required to initiate a Place Search request

key (required) — Your application's API key. 
location (required) —  This must be specified as latitude,longitude.
radius (required) — The distance (in meters) within which to return Place results.
sensor (required) — This value must be either true or false.

Each result within the results array may contain

reference contains a unique token that you can use to retrieve additional information about this place in a Place Details request. You can store this token and use it at any time in future to refresh cached data about this Place, but the same token is not guaranteed to be returned for any given Place across different searches.

  • Once you have a reference from a Place Search request, you can request more details about a particular establishment or point of interest by initiating a Place Details request.

    A Place Details request returns more comprehensive information about the indicated place such as its complete address, phone number, user rating, etc. A Place Details request is an HTTP URL of the following form:

    https://maps.googleapis.com/maps/api/place/details/output?parameters

Certain parameters are required to initiate a search request.

key (required) — Your application's API key.
reference (required) — A textual identifier that uniquely identifies a place, returned from a Place search request.
sensor (required) —  This value must be either true or false.
  • output of Place Details contains

    formatted_phone_number and international_phone_number.

Hope it would helps u.

Upvotes: 4

Related Questions