/** * Constructor * * @throws GeocodeException * @param string|LatLng $origin Origin. Can be a LatLng object or a string location e.g. San Jose, CA * @param string|LatLng $destination Destination. Can be a LatLng object or a string location e.g. San Jose, CA * @param array $renderer_options Array of renderer options corresponding to one of these: * {@link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRendererOptions} * @param array $request_options Array of request options corresponding to one of these: * {@link http://code.google.com/apis/maps/documentation/javascript/reference.html#DirectionsRendererOptions} * @return Directions */ public function __construct($origin, $destination, array $renderer_options = null, array $request_options = null) { unset($renderer_options['directions'], $renderer_options['map']); unset($request_options['origin'], $request_options['destination'], $request_options['travelMode']); if ($renderer_options) { $this->renderer_options = $renderer_options; } if ($request_options) { unset($request_options['waypoints']); $this->request_options = $request_options; } $this->request_options['travelMode'] = $this->travel_mode; if ($origin instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->request_options['origin'] = $origin->getLatLng(); } else { if (($geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($origin)) instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->request_options['origin'] = $geocode_result->getLatLng(); } else { throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result); } } if ($destination instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->request_options['destination'] = $destination->getLatLng(); } else { if (($geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($destination)) instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->request_options['destination'] = $geocode_result; } else { throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result); } } }
/** * Add a path * Adds a path to the end of the array of paths * * @throws GeocodeException * @param string|LatLng $location Location to add. This can be a location name * or a LatLng object. * @return void */ public function addPath($location) { if ($location instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->paths[] = $location->getLatLng(); } else { $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($location, true); if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->paths[] = $geocode_result->getLatLng(); } else { throw new \PHPGoogleMaps\Service\GeocodeException($geocode_result); } } }
/** * Constructor * * @param string|LatLng $center Position of the center of the circle * @param float $radius Radius of the circle in meters * @param array $options Array of optoins {@link http://code.google.com/apis/maps/documentation/javascript/reference.html#CircleOptions} * @return Circle */ public function __construct($center, $radius, array $options = null) { if ($center instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->center = $center->getLatLng(); } else { $geocode_result = \PHPGoogleMaps\Service\Geocoder::geocode($center, true); if ($geocode_result instanceof \PHPGoogleMaps\Core\PositionAbstract) { $this->center = $geocode_result->getLatLng(); } else { throw new \PHPGoogleMaps\Core\GeocodeException($geocode_result); } } $this->radius = (double) $radius; unset($options['map'], $options['center'], $options['radius']); $this->options = $options; }