2

I'm using the following code in a php file

  <script>      
var geocoder = new google.maps.Geocoder();
        geocoder.geocode( {'address': '<?php echo $element['singleCoords']; ?>' },
              function(results, status) {
                if (status == google.maps.GeocoderStatus.OK) {
                  firstLoc = results[0].geometry.location;
                  var gmap<?php echo $element['id']; ?>_marker = new google.maps.Marker({
                  position: new google.maps.LatLng(firstLoc)

When I alert firstLoc the long and lat are displayed like: 5.34.., 5,6...

But when I used the variable firstLoc in the function google.maps.LatLng() I can see in the code explorer of Chrome that only the variable name is passed and not the long and lat numbers.

In the code explorer I see this:

new google.maps.LatLng(firstLoc) 

but I want to see this:

new google.maps.LatLng(5.34.., 5,6...).

What am I doing wrong?

1 Answer 1

1

Do you need to set the position as a LatLng co-ordinate

According to Google Maps doco you can just pass results[0].geometry.location into position

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.