Cannot Read Property 'location' of Undefined Google Maps
Places Library
Overview
The functions in the Places Library, Maps JavaScript API enable your application to search for places (defined in this API as establishments, geographic locations, or prominent points of interest) independent inside a defined expanse, such every bit the bounds of a map, or effectually a stock-still point.
The Places API offers an autocomplete feature which you can utilise to give your applications the type-ahead-search behavior of the Google Maps search field. When a user starts typing an address, autocomplete volition fill in the remainder. For more than data, see the autocomplete documentation.
Getting started
If you are unfamiliar with the Maps JavaScript API or with JavaScript, we recommend reviewing JavaScript and Become an API Primal prior to getting started.
Enable APIs
Before using the Places library in the Maps JavaScript API, first ensure that the Places API is enabled in the Google Cloud Console, in the same project you set for the Maps JavaScript API.
To view your listing of enabled APIs:
- Go to the Google Deject Console.
- Click the Select a projection button, so select the aforementioned project you lot ready for the Maps JavaScript API and click Open.
- From the list of APIs on the Dashboard, look for Places API.
- If you encounter the Places API in the listing, it's already enabled. If the API is not listed, enable it:
- At the top of the page, select ENABLE APIS AND SERVICES to display the Library tab. Alternatively, from the left side menu, select Library.
- Search for Places API, so select information technology from the results list.
- Select ENABLE. When the procedure finishes, Places API appears in the list of APIs on the Dashboard.
Loading the library
The Places service is a self-independent library, split from the main Maps JavaScript API code. To apply the functionality contained within this library, y'all must offset load it using the libraries
parameter in the Maps API bootstrap URL:
<script async src="https://maps.googleapis.com/maps/api/js?primal=YOUR_API_KEY &libraries=places&callback=initMap"> </script>
Run across the Libraries Overview for more than information.
Add together Places API to the API key'southward API restrictions list
Applying API restrictions to your keys limits usage of the API key to ane or more APIs or SDKs. Requests to an API or SDK associated with the API key will exist candy. Requests to an API or SDK not associated with the API key will fail. To restrict an API key for use with the Places Library, Maps JavaScript API:
- Go to the Google Cloud Console.
- Click the projection drop-downwardly and select the project that contains the API central you want to secure.
- Click the menu button and select Google Maps Platform > Credentials.
- On the Credentials page, click the name of the API cardinal that you want to secure.
- On the Restrict and rename API central page, ready the restrictions:
- API restrictions
- Select Restrict primal.
- Click Select APIs and select both Maps JavaScript API and Places API.
(If either of the APIs is not listed, y'all need to enable it.)
- Click Save.
Usage limits and policies
Quotas
The Places Library, JavaScript API shares a usage quota with Places API as described in the Usage Limits documentation for Places API. The queries per second rate limit is applied per user session, regardless of how many users share the same projection.*
Annotation: When you lot starting time load the API, you are allocated an initial quota of requests. Once y'all use this quota, the API enforces charge per unit limits on additional requests on a per-second basis. If too many requests are made inside a certain time menses, the API returns an OVER_QUERY_LIMIT response code. The per-session charge per unit limit prevents the use of client-side services for batch requests. For batch requests, utilise our web service APIs.
Policies
Employ of the Places Library, Maps JavaScript API must exist in accordance with the policies described for the Places API.
Identify Searches
With the Places service you lot can perform the following kinds of searches:
- Find Identify from Query returns a place based on a text query (for example, the name or address of a place).
- Notice Place from Phone Number returns a place based on a phone number.
- Nearby Search returns a listing of nearby places based on a user's location.
- Text Search returns a list of nearby places based on a search string, eg. "Pizza".
- Place Details requests return more detailed information about a specific place, including user reviews.
The information returned can include establishments — such as restaurants, stores, and offices — too as 'geocode' results, which indicate addresses, political areas such as towns and cities, and other points of interest.
Find Place requests
A Observe Place request lets you search for a identify either past text query or phone number. There are two types of Find Place request:
- Find Place from Query
- Find Place from Phone Number
Discover Place from Query
Find Place from Query takes a text input and returns a place. The input can be whatever kind of Place data, for example a business name or address. To brand a Find Place from Query request, telephone call the PlaceService
's findPlaceFromQuery()
method, which takes the following parameters:
-
query
(required) A text string on which to search. -
fields
(required) Ane or more fields specifying the types of Place data to return. -
locationBias
(optional) Coordinates defining the surface area to search. This can be one of the post-obit:- A set of lat/lng coordinates specified as LatLngLiteral or LatLng object
- Rectangular bounds (2 lat/lng pairs, or a LatLngBounds object)
- Radius (in meters) centered on a lat/lng
You must also pass a callback method to findPlaceFromQuery()
, to handle the results object and google.maps.places.PlacesServiceStatus
response.
The following example shows a call to findPlaceFromQuery()
, searching for "Museum of Contemporary Fine art Australia", and including the name
and geometry
fields.
var map; var service; var infowindow; function initMap() { var sydney = new google.maps.LatLng(-33.867, 151.195); infowindow = new google.maps.InfoWindow(); map = new google.maps.Map( document.getElementById('map'), {center: sydney, zoom: 15}); var request = { query: 'Museum of Contemporary Fine art Australia', fields: ['name', 'geometry'], }; var service = new google.maps.places.PlacesService(map); service.findPlaceFromQuery(asking, office(results, status) { if (status === google.maps.places.PlacesServiceStatus.OK) { for (var i = 0; i < results.length; i++) { createMarker(results[i]); } map.setCenter(results[0].geometry.location); } }); }
View example
Notice Place from Phone Number
Find Place from Phone Number takes a telephone number and returns a identify. To make a Find Place from Phone Number request, call the PlaceService
'south findPlaceFromPhoneNumber()
method, which takes the following parameters:
-
phoneNumber
(required) A telephone number, in E.164 format. -
fields
(required) One or more than fields specifying the types of Place data to return. -
locationBias
(optional) Coordinates defining the area to search. This tin can be 1 of the following:- A set of lat/lng coordinates specified as LatLngLiteral or LatLng object
- Rectangular bounds (four lat/lng points, or a LatLngBounds object)
- Radius (in meters) centered on a lat/lng
You must likewise pass a callback method to findPlaceFromPhoneNumber()
, to handle the results object and google.maps.places.PlacesServiceStatus
response.
Fields (Find Identify methods)
Use the fields
parameter to specify an array of identify data types to return. For example: fields: ['formatted_address', 'opening_hours', 'geometry']
. Utilize a dot when specifying compound values. For example: opening_hours.weekday_text
.
Fields represent to Place Search results, and are divided into three billing categories: Basic, Contact, and Atmosphere. Basic fields are billed at base of operations rate, and incur no additional charges. Contact and Atmosphere fields are billed at a higher charge per unit. See the pricing sheet for more information. Attributions (html_attributions
) are always returned with every telephone call, regardless of whether the field has been requested.
Bones
The Basic category includes the following fields:
business_status
, formatted_address
, geometry
, icon
,icon_mask_base_uri
, icon_background_color
, name
, permanently_closed
(deprecated), photos
, place_id
, plus_code
, types
Contact
The Contact category includes the following field: opening_hours
(deprecated in the Places Library, Maps JavaScript API. Utilise a Place Details request to get the opening_hours
results).
Atmosphere
The Atmosphere category includes the following fields: price_level
, rating
, user_ratings_total
The findPlaceFromQuery()
and findPlaceFromPhoneNumber()
methods each take the same set up of fields, and can return the same fields in their respective responses.
Set location bias (Notice Place methods)
Utilize the locationBias
parameter to make Find Place favor results in a item area. You can set up locationBias
in the following ways:
Bias results to a specific area:
locationBias: {lat: 37.402105, lng: -122.081974}
Define a rectangular area to search:
locationBias: {north: 37.41, southward: 37.xl, east: -122.08, w: -122.09}
You tin can likewise apply a LatLngBounds.
Define a radius to search (in meters), centered on a particular area:
locationBias: {radius: 100, center: {lat: 37.402105, lng: -122.081974}}
Nearby Search Requests
A Nearby Search lets you lot search for places within a specified area by keyword or type. A Nearby Search must e'er include a location, which can be specified in one of two ways:
- a
LatLngBounds
. - a round surface area divers as the combination of the
location
property — specifying the center of the circle as aLatLng
object — and a radius, measured in meters.
A Places Nearby search is initiated with a call to the PlacesService
's nearbySearch()
method, which will return an array of PlaceResult
objects. Note that the nearbySearch()
method replaces the search()
method as of version 3.nine.
service = new google.maps.places.PlacesService(map); service.nearbySearch(request, callback);
This method takes a request with the post-obit fields:
- Either of:
-
premises
, which must exist agoogle.maps.LatLngBounds
object defining the rectangular search area; or - a
location
and aradius
; the former takes agoogle.maps.LatLng
object, and the latter takes a simple integer, representing the circumvolve's radius in meters. The maximum allowed radius is l 000 meters. Note that whenrankBy
is gear up to Altitude, you must specify alocation
but you cannot specify aradius
orbounds
.
-
-
keyword
(optional) — A term to be matched confronting all available fields, including but not limited to proper noun, type, and accost, too as customer reviews and other third-political party content. -
minPriceLevel
andmaxPriceLevel
(optional) — Restricts results to only those places within the specified range. Valid values range betwixt 0 (most affordable) to 4 (most expensive), inclusive. -
name
(optional) — A term to be matched confronting the names of places. Results volition be restricted to those containing the passed proper name value. Note that a place may have additional names associated with information technology, beyond its listed name. The API will endeavour to friction match the passedname
value against all of these names; every bit a result, places may be returned in the results whose listed names practice not match the search term, but whose associated names practise. -
openNow
(optional) — A boolean value, indicating that the Places service should only return those places that are open for business at the time the query is sent. Places that do not specify opening hours in the Google Places database will not be returned if y'all include this parameter in your query. SettingopenNow
tofalse
has no consequence. -
rankBy
(optional) — Specifies the club in which results are listed. Possible values are:-
google.maps.places.RankBy.PROMINENCE
(default). This option sorts results based on their importance. Ranking will favor prominent places within the set up radius over nearby places that friction match just that are less prominent. Prominence tin be affected by a identify's ranking in Google's index, global popularity, and other factors. Whengoogle.maps.places.RankBy.PROMINENCE
is specified, theradius
parameter is required. -
google.maps.places.RankBy.Distance
. This option sorts results in ascending club by their distance from the specifiedlocation
(required). Note that you cannot specify a custombounds
and/orradius
if you specifyRankBy.DISTANCE
. When y'all specifyRankBy.Altitude
, one or more ofkeyword
,name
, ortype
is required.
-
-
type
— Restricts the results to places matching the specified type. Only one type may be specified (if more one type is provided, all types post-obit the showtime entry are ignored). See the list of supported types.
You must besides laissez passer a callback method to nearbySearch()
, to handle the results object and google.maps.places.PlacesServiceStatus
response.
var map; var service; var infowindow; function initialize() { var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316); map = new google.maps.Map(document.getElementById('map'), { center: pyrmont, zoom: fifteen }); var request = { location: pyrmont, radius: '500', type: ['eating place'] }; service = new google.maps.places.PlacesService(map); service.nearbySearch(request, callback); } function callback(results, status) { if (status == google.maps.places.PlacesServiceStatus.OK) { for (var i = 0; i < results.length; i++) { createMarker(results[i]); } } }
View example
Text Search Requests
The Google Places Text Search service is a spider web service that returns information near a set up of places based on a string — for case "pizza in New York" or "shoe stores near Ottawa". The service responds with a listing of places matching the text string and any location bias that has been set. The search response volition include a list of places. You can send a Identify Details request for more information most any of the places in the response.
Text Searches are initiated with a call to the PlacesService
's textSearch()
method.
service = new google.maps.places.PlacesService(map); service.textSearch(request, callback);
This method takes a request with the following fields:
-
query
(required) The text string on which to search, for case: "restaurant". The Places service will return candidate matches based on this string and order the results based on their perceived relevance. This parameter becomes optional if thetype
parameter is also used in the search request. - Optionally:
-
openNow
— A boolean value, indicating that the Places service should but return those places that are open for business organisation at the time the query is sent. Places that exercise non specify opening hours in the Google Places database volition not be returned if you include this parameter in your query. SettingopenNow
tofaux
has no effect. -
minPriceLevel
andmaxPriceLevel
— Restricts results to only those places within the specified price level. Valid values are in the range from 0 (most affordable) to 4 (about expensive), inclusive. - Either of:
-
bounds
— Agoogle.maps.LatLngBounds
object defining the rectangle in which to search; or - a
location
and aradius
— You may bias results to a specified circle past passing alocation
and aradius
parameter. This volition instruct the Places service to prefer showing results within that circle. Results outside the defined area may still be displayed. The location takes agoogle.maps.LatLng
object, and the radius takes a unproblematic integer, representing the circle's radius in meters. The maximum allowed radius is 50 000 meters.
-
-
blazon
— Restricts the results to places matching the specified type. Merely 1 type may exist specified (if more than than one type is provided, all types following the first entry are ignored). See the list of supported types.
-
You must also laissez passer a callback method to textSearch()
, to handle the results object and a google.maps.places.PlacesServiceStatus
response.
var map; var service; var infowindow; function initialize() { var pyrmont = new google.maps.LatLng(-33.8665433,151.1956316); map = new google.maps.Map(certificate.getElementById('map'), { middle: pyrmont, zoom: 15 }); var request = { location: pyrmont, radius: '500', query: 'eating house' }; service = new google.maps.places.PlacesService(map); service.textSearch(request, callback); } 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]); } } }
Search Responses
Status Codes
The PlacesServiceStatus
response object contains the status of the request, and may comprise debugging information to help you rail downward why the identify request failed. Possible condition values are:
-
INVALID_REQUEST
: This asking was invalid. -
OK
: The response contains a valid consequence. -
OVER_QUERY_LIMIT
: The webpage has gone over its asking quota. -
REQUEST_DENIED
: The webpage is non allowed to use the PlacesService. -
UNKNOWN_ERROR
: The PlacesService asking could not be processed due to a server error. The request may succeed if you lot effort once again. -
ZERO_RESULTS
: No result was found for this request.
Place Search Results
The findPlace()
, nearbySearch()
and textSearch()
functions return an assortment of PlaceResult
objects.
Each PlaceResult
object may include the following properties:
-
business_status
indicates the operational condition of the place, if information technology is a business. It can contain i of the following values:-
OPERATIONAL
-
CLOSED_TEMPORARILY
-
CLOSED_PERMANENTLY
business_status
is not returned. -
-
formatted_address
is a string containing the homo-readable address of this place. Theformatted_address
property is only returned for a Text Search.Often this address is equivalent to the postal address. Note that some countries, such every bit the United kingdom, exercise not let distribution of true postal addresses due to licensing restrictions.
The formatted accost is logically equanimous of one or more address components. For case, the accost "111 8th Avenue, New York, NY" consists of the post-obit components: "111" (the street number), "8th Avenue" (the route), "New York" (the city) and "NY" (the US land).
Practice not parse the formatted address programmatically. Instead you should apply the individual address components, which the API response includes in addition to the formatted address field.
-
geometry
: The place'south geometry-related data. This includes:-
location
provides the latitude and longitude of the place. -
viewport
defines the preferred viewport on the map when viewing this place.
-
-
permanently_closed
(deprecated) is a boolean flag indicating whether the identify has shut down either permanently or temporarily (valuetrue
). Do not usepermanently_closed
. Instead, usebusiness_status
to get the operational status of businesses. -
plus_code
(encounter Open Location Code and plus codes) is an encoded location reference, derived from latitude and longitude coordinates, that represents an surface area: ane/8000th of a degree by 1/8000th of a degree (most 14m ten 14m at the equator) or smaller. Plus codes can be used as a replacement for street addresses in places where they do not exist (where buildings are not numbered or streets are not named).The plus code is formatted as a global code and a compound code:
-
global_code
is a 4 character expanse code and half-dozen character or longer local code (849VCWC8+R9). -
compound_code
is a vi character or longer local code with an explicit location (CWC8+R9, Mountain View, CA, U.s.a.). Practice not programmatically parse this content.
-
-
html_attributions
: An array of attributions that you should display when displaying the search results. Each entry in the array contains the HTML text for a single attribution. Note: This is an aggregation of all the attributions for the unabridged search response. AllPlaceResult
objects in the response therefore contain identical attribution lists. -
icon
returns the URL for a colored 71px ten 71px PNG icon. -
icon_mask_base_uri
returns the base URL for a not-colored icon, minus the .svg or .png extension. -
icon_background_color
returns the default HEX color code for the place's category. -
name
: The identify's name. -
opening_hours
may incorporate the following information:-
open_now
is a boolean value indicating if the identify is open at the electric current fourth dimension (Deprecated in the Places Library, Maps JavaScript API, employutc_offset_minutes
instead).
-
-
place_id
is a textual identifier that uniquely identifies a place. To retrieve data about the identify, pass this identifier in the Place Details request. Learn more about how to reference a place with a place ID. -
rating
contains the place'due south rating, from 0.0 to 5.0, based on aggregated user reviews. -
types
An assortment of types for this place (e.one thousand.,["political", "locality"]
or["restaurant", "lodging"]
). This array may comprise multiple values, or may be empty. New values may be introduced without prior observe. See the list of supported types. -
vicinity
: A simplified address for the place, including the street proper noun, street number, and locality, but not the province/state, postal code, or state. For instance, Google's Sydney, Australia office has avicinity
value of5/48 Pirrama Road, Pyrmont
.
Accessing Boosted Results
By default, each place search returns upwards to 20 results per query. However, each search can render as many equally threescore results, split across 3 pages. Additional pages are bachelor via the PlaceSearchPagination
object. In order to access additional pages you must capture the PlaceSearchPagination
object via a callback function. The PlaceSearchPagination
object is defined as:
-
hasNextPage
a boolean belongings that indicates if further results are available.truthful
when at that place is an additional results page. -
nextPage()
a function that volition return the adjacent prepare of results. Subsequently executing a search, you must wait two seconds before the side by side folio of results will be bachelor.
To meet the next fix of results, call nextPage
. Each page of results must be displayed before displaying the next page of results. Notation that each search counts as a single request confronting your usage limits.
The example below demonstrates how to modify your callback role to capture the PlaceSearchPagination
object, so that you tin can issue multiple search requests.
Place Details
In addition to providing a listing of places within an expanse, the Places service tin also return detailed information well-nigh a specific identify. Once a place has been returned in a identify search response, its identify ID can be used to asking additional details nearly that place, such as its complete address, phone number, user rating and reviews, etc.
Place Details Requests
Place Details are requested with a telephone call to the service's getDetails()
method.
service = new google.maps.places.PlacesService(map); service.getDetails(request, callback);
This method takes a request, containing the desired place'south placeId
, and fields indicating which types of Places information to return. Learn more than about how to reference a place with a place ID.
It also takes a callback method, which needs to handle the status lawmaking passed in the google.maps.places.PlacesServiceStatus
response, equally well as the google.maps.places.PlaceResult
object.
var request = { placeId: 'ChIJN1t_tDeuEmsRUsoyG83frY4', fields: ['name', 'rating', 'formatted_phone_number', 'geometry'] }; service = new google.maps.places.PlacesService(map); service.getDetails(asking, callback); function callback(place, status) { if (status == google.maps.places.PlacesServiceStatus.OK) { createMarker(place); } }
View example
Fields (Place details)
The fields
parameter takes an array of strings (field names).
Utilise the fields
parameter to specify an array of place data types to return. For example: fields: ['address_component', 'opening_hours', 'geometry']
. Use a dot when specifying chemical compound values. For example: opening_hours.weekday_text
.
Fields correspond to Place Details results, and are divided into three billing categories: Basic, Contact, and Atmosphere. Basic fields are billed at base charge per unit, and incur no additional charges. Contact and Atmosphere fields are billed at a higher rate. Run into the pricing sheet for more information. Attributions (html_attributions
) are always returned with every call, regardless of whether it has been requested.
Bones
The Basic category includes the following fields:
address_component
, adr_address
, business_status
, formatted_address
, geometry
, icon
, icon_mask_base_uri
, icon_background_color
,name
, permanently_closed
(deprecated), photo
, place_id
, plus_code
, type
, url
, utc_offset
(deprecated in the Places Library, Maps JavaScript API), utc_offset_minutes
, vicinity
Contact
The Contact category includes the following fields:
formatted_phone_number
, international_phone_number
, opening_hours
, website
Atmosphere
The Atmosphere category includes the following fields: price_level
, rating
, review
, user_ratings_total
Larn more near place fields. For more information about how Place data requests are billed, meet Usage and Billing.
Identify Details Responses
Status Codes
The PlacesServiceStatus
response object contains the status of the asking, and may contain debugging information to assistance you track downwards why the Identify Details request failed. Possible condition values are:
-
INVALID_REQUEST
: This request was invalid. -
OK
: The response contains a valid outcome. -
OVER_QUERY_LIMIT
: The webpage has gone over its asking quota. -
NOT_FOUND
The referenced location was non found in the Places database. -
REQUEST_DENIED
: The webpage is non allowed to apply the PlacesService. -
UNKNOWN_ERROR
: The PlacesService request could not exist processed due to a server error. The request may succeed if you try again. -
ZERO_RESULTS
: No issue was found for this request.
Place Details Results
A successful getDetails()
call returns a PlaceResult
object with the following properties:
-
address_components
: An array containing the separate components applicative to this accost.Each address component typically contains the post-obit fields:
-
types[]
is an array indicating the type of the address component. Run into the list of supported types. -
long_name
is the full text description or proper noun of the address component every bit returned by the Geocoder. -
short_name
is an abbreviated textual name for the accost component, if bachelor. For example, an address component for the state of Alaska may accept along_name
of "Alaska" and ashort_name
of "AK" using the two-letter postal abbreviation.
Annotation the following facts about the
address_components[]
array:- The array of address components may contain more components than the
formatted_address
. - The array does not necessarily include all the political entities that comprise an address, autonomously from those included in the
formatted_address
. To retrieve all the political entities that contain a specific accost, y'all should utilise reverse geocoding, passing the latitude/longitude of the address equally a parameter to the request. - The format of the response is not guaranteed to remain the same between requests. In particular, the number of
address_components
varies based on the address requested and can change over time for the same address. A component tin can change position in the array. The blazon of the component tin can change. A particular component may be missing in a later response.
-
-
business_status
indicates the operational status of the place, if it is a business. It can contain one of the following values:-
OPERATIONAL
-
CLOSED_TEMPORARILY
-
CLOSED_PERMANENTLY
business_status
is not returned. -
-
formatted_address
: The human-readable address of this identify.Oftentimes this address is equivalent to the postal address. Note that some countries, such every bit the United Kingdom, practise non allow distribution of true postal addresses due to licensing restrictions.
The formatted address is logically composed of one or more address components. For example, the address "111 eighth Avenue, New York, NY" consists of the post-obit components: "111" (the street number), "eighth Avenue" (the route), "New York" (the city) and "NY" (the Us state).
Exercise not parse the formatted address programmatically. Instead you lot should utilise the individual address components, which the API response includes in addition to the formatted accost field.
-
formatted_phone_number
: The place'due south phone number, formatted according to the number'south regional convention. -
geometry
: The place'due south geometry-related information. This includes:-
location
provides the latitude and longitude of the place. -
viewport
defines the preferred viewport on the map when viewing this place.
-
-
permanently_closed
(deprecated) is a boolean flag indicating whether the place has shut downward either permanently or temporarily (valuetrue
). Do not usepermanently_closed
. Instead, applybusiness_status
to get the operational condition of businesses. -
plus_code
(come across Open up Location Code and plus codes) is an encoded location reference, derived from breadth and longitude coordinates, that represents an surface area: 1/8000th of a degree by 1/8000th of a degree (nearly 14m 10 14m at the equator) or smaller. Plus codes can exist used as a replacement for street addresses in places where they do not exist (where buildings are not numbered or streets are non named).The plus code is formatted as a global code and a compound lawmaking:
-
global_code
is a 4 graphic symbol area code and 6 character or longer local lawmaking (849VCWC8+R9). -
compound_code
is a vi character or longer local lawmaking with an explicit location (CWC8+R9, Mount View, CA, USA). Practise not programmatically parse this content.
-
-
html_attributions
: Attribution text to be displayed for this identify result. -
icon
: URL to an image resource that tin can exist used to represent this place'south blazon. -
international_phone_number
contains the place's phone number in international format. International format includes the country lawmaking, and is prefixed with the plus (+) sign. For case, theinternational_phone_number
for Google'south Sydney, Australia office is+61 2 9374 4000
. -
name
: The place's name. -
utc_offset
Deprecated in the Places Library, Maps JavaScript API, applyutc_offset_minutes
instead. -
utc_offset_minutes
contains the number of minutes this identify'southward current timezone is beginning from UTC. For example, for places in Sydney, Australia during daylight saving time this would be 660 (+xi hours from UTC), and for places in California outside of daylight saving time this would exist -480 (-viii hours from UTC). -
opening_hours
contains the following information:-
open_now
(Deprecated in the Places Library, Maps JavaScript API; use opening_hours.isOpen() instead. Run across this video for how to useisOpen
with Place Details.) is a boolean value indicating whether the place is open at the current time. -
periods[]
is an array of opening periods roofing seven days, starting from Sun, in chronological order. Each menstruation contains:-
open
contains a pair of twenty-four hour period and time objects describing when the place opens:-
solar day
a number from 0–6, respective to the days of the calendar week, starting on Dominicus. For case, 2 means Tuesday. -
time
may contain a fourth dimension of day in 24-hr hhmm format (values are in the range 0000–2359). Thetime
will be reported in the place's timezone.
-
-
close
may contain a pair of 24-hour interval and time objects describing when the place closes. Notation: If a identify is always open up, theclose
section volition be missing from the response. Applications can rely on always-open being represented as anopen
period containingsolar day
with value 0 andtime
with value 0000, and noclose
.
-
-
weekday_text
is an array of 7 strings representing the formatted opening hours for each day of the week. If alanguage
parameter was specified in the Identify Details asking, the Places Service will format and localize the opening hours appropriately for that language. The ordering of the elements in this array depends on thelanguage
parameter. Some languages beginning the week on Monday while others start on Sunday.
-
-
permanently_closed
(deprecated) is a boolean flag indicating whether the place has shut down either permanently or temporarily (valuetruthful
). Practise not usepermanently_closed
. Instead, employbusiness_status
to become the operational condition of businesses. -
photos[]
: an assortment ofPlacePhoto
objects. APlacePhoto
can exist used to obtain a photo with thegetUrl()
method, or you can audit the object for the following values:-
height
: the maximum height of the image, in pixels. -
width
: the maximum width of the image, in pixels. -
html_attributions
: Attribution text to be displayed with this identify photograph.
-
-
place_id
: A textual identifier that uniquely identifies a place and can exist used to retrieve information about the place via a Place Details request. Learn more almost how to reference a place with a identify ID. -
rating
: The place'due south rating, from 0.0 to five.0, based on aggregated user reviews. -
reviews
an array of up to five reviews. Each review consists of several components:-
aspects[]
contains an array ofPlaceAspectRating
objects, each of which provides a rating of a single aspect of the establishment. The first object in the array is considered the primary aspect. EachPlaceAspectRating
is defined equally:-
type
the name of the aspect that is being rated. The following types are supported:appeal
,atmosphere
,decor
,facilities
,nutrient
,overall
,quality
andservice
. -
rating
the user'south rating for this detail attribute, from 0 to three.
-
-
author_name
the name of the user who submitted the review. Anonymous reviews are attributed to "A Google user". If a language parameter was set, and so the phrase "A Google user" will return a localized string. -
author_url
the URL to the users Google+ profile, if available. -
linguistic communication
an IETF language code indicating the language used in the user'south review. This field contains the primary language tag only, and not the secondary tag indicating state or region. For example, all the English reviews are tagged as 'en', and not 'en-AU' or 'en-UK' and then on. -
rating
the user's overall rating for this place. This is a whole number, ranging from 1 to 5. -
text
the user'southward review. When reviewing a location with Google Places, text reviews are considered optional; therefore, this field may by empty.
-
-
types
An array of types for this place (due east.thousand.,["political", "locality"]
or["restaurant", "lodging"]
). This array may contain multiple values, or may exist empty. New values may exist introduced without prior find. Come across the list of supported types. -
url
: URL of the official Google page for this place. This is the Google-owned page that contains the all-time available information about the place. Applications must link to or embed this page on any screen that shows detailed results about the place to the user. -
vicinity
: A simplified address for the identify, including the street proper noun, street number, and locality, but not the province/land, postal code, or land. For example, Google's Sydney, Commonwealth of australia office has avicinity
value of5/48 Pirrama Road, Pyrmont
. Thevicinity
property is only returned for a Nearby Search. -
website
lists the administrative website for this identify, such equally a business' homepage.
Note: Multidimensional ratings may not be available for all locations. If there are too few reviews then the details response volition either include a legacy rating on a 0.0 to 5.0 calibration (if available) or no rating at all.
Referencing a Identify with a Place ID
A place ID is a unique reference to a place on a Google Map. Place IDs are available for well-nigh locations, including businesses, landmarks, parks, and intersections.
To use a identify ID in your app yous must first look upwardly the ID, which is available in PlaceResult
of a Place Search or Details request. You can then use this place ID to look up Identify Details.
Place IDs are exempt from the caching restrictions stated in Section three.2.3(a) of the Google Maps Platform Terms of Service. You tin therefore store place ID values for after utilise. For all-time practises when storing identify IDs, see the place ID overview.
var map; function initialize() { // Create a map centered in Pyrmont, Sydney (Australia). map = new google.maps.Map(document.getElementById('map'), { centre: {lat: -33.8666, lng: 151.1958}, zoom: 15 }); // Search for Google's part in Australia. var request = { location: map.getCenter(), radius: '500', query: 'Google Sydney' }; var service = new google.maps.places.PlacesService(map); service.textSearch(asking, callback); } // Checks that the PlacesServiceStatus is OK, and adds a marker // using the identify ID and location from the PlacesService. function callback(results, status) { if (status == google.maps.places.PlacesServiceStatus.OK) { var marker = new google.maps.Marker({ map: map, identify: { placeId: results[0].place_id, location: results[0].geometry.location } }); } } google.maps.event.addDomListener(window, 'load', initialize);
Place Photos
The Place Photo feature allows you to add high quality photographic content to your site. The Photo service gives yous access to the millions of photos stored in the Places and Google+ Local database. When you get identify information using a Identify Details asking, photograph references volition be returned for relevant photographic content. The Nearby Search and Text Search requests too render a unmarried photo reference per identify, when relevant. Using the Photo service y'all can then access the referenced photos and resize the image to the optimal size for your awarding.
An array of PlacePhoto
objects will be returned every bit office of the PlaceResult
object for any getDetails()
, textSearch()
or nearbySearch()
request made against a PlacesService
.
Annotation: The number of photos returned varies by request.
- A Nearby Search or a Text Search will return at most 1
PlacePhoto
object. - A Details request volition render up to ten
PlacePhoto
objects.
You lot can asking the URL for the associated prototype past calling the PlacePhoto.getUrl()
method, and passing a valid PhotoOptions
object. The PhotoOptions
object allows you lot to specify the maximum desired meridian and width of the epitome. If you specify a value for both maxHeight
and a maxWidth
, the photo service will resize the image to the smaller of the ii sizes, while maintaining the original aspect ratio.
The post-obit code snippet accepts a place object, and adds a marker to the map if a photo exists. The default marking epitome is replaced by a small-scale version of the photo.
office createPhotoMarker(place) { var photos = place.photos; if (!photos) { return; } var marker = new google.maps.Mark({ map: map, position: place.geometry.location, title: identify.proper name, icon: photos[0].getUrl({maxWidth: 35, maxHeight: 35}) }); }
Photos returned past the Photo service are sourced from a multifariousness of locations, including concern owners and user contributed photos. In virtually cases, these photos can be used without attribution, or will have the required attribution included equally a part of the image. However, if the returned photo
element includes a value in the html_attributions
field, you must include the additional attribution in your application wherever yous display the prototype.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed nether the Apache 2.0 License. For details, encounter the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Concluding updated 2022-02-28 UTC.
Source: https://developers.google.com/maps/documentation/javascript/places
0 Response to "Cannot Read Property 'location' of Undefined Google Maps"
Post a Comment