简体   繁体   中英

The Google Maps API server rejected your request. Invalid request. Missing the 'size' parameter

I'm writing an application on node.js I need to insert a Static Google Map. The code looks like this

  .panel.panel-primary
    .panel-heading
      h2.panel-title On the map
    .panel-body
      img.img-responsive.img-rounded(src="http://maps.googleapis.com/maps/api/staticmap?center=#{location.coords.lat},#{location.coords.lng}&zoom=17&size=400x350&sensor=false&markers=#{location.coords.lat},#{location.coords.lng}&scale=2&key=AIzaSyDt0D6sy4v8BZFVJiAea93aiR63E-GpBL8")

Controller, from where information about coordinates is taken

res.render('location-info', {
    title: 'empty',
    pageHeader: {title: 'empty'},
    sidebar: {
        context: 'empty',
        callToAction: 'empty.'
    },
    location: {
        name: 'empty',
        address: 'empty',
        rating: 5,
        facilities: ['empty'],
        coords: {lat: 55.752813, lng: 37.791908},
        openingTimes: [{
            days: 'empty',
            opening: '19:00',
            closing: '01:00',
            closet: false
        },{

How it looks like. When im try to copy someone else's code, everything works fine. Help! Thank you in advance.

Template literals use $ , eg ${varNameHere} - not #{location.coords.lat} .

Try:

src="http://maps.googleapis.com/maps/api/staticmap?center=${location.coords.lat},${location.coords.lng}&zoom=17&size=400x350&sensor=false&markers=${location.coords.lat},${location.coords.lng}&scale=2&key=AIzaSyDt0D6sy4v8BZFVJiAea93aiR63E-GpBL8"

You can check the error messages from Google Map here .

In your case, the size parameter is not within the expected range of numeric values, or is missing from the request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM