1

In google maps API, to specify the position of a marker with the position (0,0) we can use

  • position : new google.maps.LatLng(0,0)

OR

  • position : {lat:0, lng:0}

The two expressions work fine ...

My questions :

  • What is the difference between the two expressions ?
  • Which one is better to use.

Thank you

2

1 Answer 1

4

The difference: The first uses a LatLng-instance(with methods lat and lng), the 2nd is a LatLngLiteral, an object-literal with properties lat and lng. Both are completely different, Marker.setPosition accepts both kinds of objects.

Which one is better to use:

It depends on your opinion what is "better", just some points:

  • the API first checks if the position is a LatLng. When it does, it uses the LatLng, otherwise it converts the LatLngLiteral into a LatLng. So it's clear, for performance it's better to use a LatLng.
  • the LatLngLiteral may be used without the maps-API(e.g. you may store it without a already loaded maps-API, you also may transport it via JSON)
  • LatLngs are accepted by any object/method of the maps-API which expects a coordinate, but there are different methods/objects which do not accept a LatLngLiteral, so it may be better to use always LatLngs to avoid errors.
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.