0

I'm looking at the Google Maps Javascript API and I've come across this:

LatLng   computeOffset(from:LatLng, distance:number, heading:number, radius?:number)

The above method comes from the Google Maps Javascript API documentation at: Maps Documentation

It works without inserting the last argument radius?:number.

My question is what is radius?:number. Is this some conditional statement for an argument? Is this some ternary argument?

The Android Maps API has a similar function without the radius?:number argument:

static LatLng computeOffset(LatLng from, double distance, double heading)

What is ?: in this context and how is it used?

johnsonjp34
  • 3,139
  • 5
  • 22
  • 48
  • 1
    I'd guess it means that radius is optional. – m69's been on strike for years Jul 20 '15 at 18:30
  • 2
    Java? JavaScript? These are two different languages. What are you asking about? ...in any case, the code isn't JavaScript, so the question doesn't make much sense. Give some actual reference to what you're seeing. –  Jul 20 '15 at 18:30
  • Yeah, this doesn't look like a ternary operation. It's just the _documentation_ indicating the radius is optional, like @m69 says. – Andy Jul 20 '15 at 18:30
  • @squint This is from the Google Maps Javascript API so Javascript. Thanks! – johnsonjp34 Jul 20 '15 at 18:34
  • 1
    Take a look at this thread about option parameters in javascript: http://stackoverflow.com/questions/12797118/how-can-i-declare-optional-function-parameters-in-javascript in resume, the required parameters come first then the optionals. The ? in the function declaration is a convention in the docs (it's not a javascript pattern) to say that the param is optional. – Christian Benseler Jul 20 '15 at 18:36
  • @squint it comes from the spherical namespace list of methods found at: https://developers.google.com/maps/documentation/javascript/3.exp/reference . The question mark is used in several other methods. I assume from the other comments it is just the documentations way of stating that the parameter is optional. – johnsonjp34 Jul 20 '15 at 18:42

1 Answers1

0

The radius defaults to the Earth's radius in meters. if you change it to miles answer will be in miles.

Mark Adler
  • 161
  • 2
  • 3