private function stringToLatLongValue($location) { if ($this->supportGeocoding && Geocoders::canGeocode()) { $location = Geocoders::attemptToGeocode($location); if ($location === false) { throw new ParseException('Failed to parse or geocode'); } assert($location instanceof LatLongValue); return $location; } $parser = new GeoCoordinateParser(new \ValueParsers\ParserOptions()); return $parser->parse($location); }
/** * @see ParserHookTest::processingProvider * @since 3.0 * @return array */ public function processingProvider() { $argLists = array(); $coordinateParser = new GeoCoordinateParser(new \ValueParsers\ParserOptions()); foreach ($this->distances as $distance => $expectedDistance) { foreach ($this->bearings as $bearing) { foreach ($this->locations as $location) { $values = array('distance' => (string) $distance, 'bearing' => (string) $bearing, 'location' => (string) $location); $expected = array('distance' => $expectedDistance, 'bearing' => (double) $bearing, 'location' => new Location($coordinateParser->parse($location)->getValue())); $argLists[] = array($values, $expected); } } } return $argLists; }
/** * @since 3.0 * * @param string[] $coordinateStrings * * @return LatLongValue[] */ protected function parseCoordinates(array $coordinateStrings) { $coordinates = array(); $coordinateParser = new GeoCoordinateParser(new \ValueParsers\ParserOptions()); $supportsGeocoding = $this->supportGeocoding && \Maps\Geocoders::canGeocode(); foreach ($coordinateStrings as $coordinateString) { if ($supportsGeocoding) { $coordinate = \Maps\Geocoders::attemptToGeocode($coordinateString); if ($coordinate === false) { // TODO } else { $coordinates[] = $coordinate; } } else { $coordinates[] = $coordinateParser->parse($coordinateString); } } return $coordinates; }
/** * @param string $coordinates */ protected function tryParseAndSetDataItem($coordinates) { $options = new \ValueParsers\ParserOptions(); $parser = new GeoCoordinateParser($options); try { $value = $parser->parse($coordinates); $this->m_dataitem = new SMWDIGeoCoord($value->getLatitude(), $value->getLongitude()); } catch (ParseException $parseException) { $this->addError(wfMessage('maps_unrecognized_coords', $coordinates, 1)->text()); // Make sure this is always set // TODO: Why is this needed?! $this->m_dataitem = new SMWDIGeoCoord(array('lat' => 0, 'lon' => 0)); } }
/** * This function first determines wether the provided string is a pair or coordinates * or an address. If it's the later, an attempt to geocode will be made. The function will * return the coordinates or false, in case a geocoding attempt was made but failed. * * @since 0.7 * * @param string $coordsOrAddress * @param string $geoservice * @param string|false $mappingService * @param boolean $checkForCoords * * @return LatLongValue|false */ public static function attemptToGeocode($coordsOrAddress, $geoservice = '', $mappingService = false, $checkForCoords = true) { if ($checkForCoords) { $coordinateParser = new GeoCoordinateParser(new \ValueParsers\ParserOptions()); try { return $coordinateParser->parse($coordsOrAddress); } catch (ParseException $parseException) { return self::geocode($coordsOrAddress, $geoservice, $mappingService); } } else { return self::geocode($coordsOrAddress, $geoservice, $mappingService); } }
private function stringToLatLongValue($location) { $parser = new GeoCoordinateParser(new \ValueParsers\ParserOptions()); return $parser->parse($location); }
private function assertRoundTrip(LatLongValue $value, FormatterOptions $options) { $formatter = new GeoCoordinateFormatter($options); $parser = new GeoCoordinateParser(); $formatted = $formatter->format($value); $parsed = $parser->parse($formatted); // NOTE: $parsed may be != $coord, because of rounding, so we can't compare directly. $formattedParsed = $formatter->format($parsed); $this->assertEquals($formatted, $formattedParsed); }