0

I am saving a longitude and latitude from Google Maps on form submit, I am trying to save the long and lat on validation fail using old like this..

map.setCenter({ lat:{{old('lat')}}, lng:{{old('lng')}} });

This is giving me...

InvalidValueError: setCenter: not a LatLng or LatLngLiteral: in property lat: not a number

When I examine the source I can see that the longitude and latitude are returned correctly, but Google Maps is not seeing them as a number.

Do I need to cast them as integers first?

fightstarr20
  • 11,682
  • 40
  • 154
  • 278

1 Answers1

0

Try using "{!! old('lat') !!}" and "{!! old('lng') !!}".

I would guess that your values are being wrapped in quotes like this:

map.setCenter({ lat:"12345", lng:"54321" });

Blade does this to "protect" the content.

using the double bang syntax makes it print raw data.

In other words, it needs to look like this:

map.setCenter({ lat:12345, lng:54321 });

Note that there are no quotes in this example.

Also insure that, in the controller that's passing these values, the values are being cast to integers. It'll ensure that the template is, indeed, receiving the values as integers.

Michael Miller
  • 399
  • 1
  • 9
  • I have had a look at the output and it isn't being wrapped in quotes, I think it needs casting to int but as it is 'old' then it isnt running through a controller? – fightstarr20 Feb 01 '19 at 20:04
  • See if this link does it for you: https://stackoverflow.com/questions/44878472/errorinvalidvalueerror-setcenter-not-a-latlng-or-latlngliteral-in-property-l; it looks like they're dealing with a similar issue. – Michael Miller Feb 01 '19 at 20:16