Skip to content

Commit

Permalink
Use a more flexible coordinate detection approach
Browse files Browse the repository at this point in the history
  • Loading branch information
nirvn committed Jul 28, 2020
1 parent 182167f commit 8d7f090
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/app/locator/qgsinbuiltlocatorfilters.cpp
Expand Up @@ -731,18 +731,14 @@ void QgsGotoLocatorFilter::fetchResults( const QString &string, const QgsLocator
const QgsCoordinateReferenceSystem wgs84Crs( QStringLiteral( "EPSG:4326" ) );

// Coordinates such as 106.8468,-6.3804
QStringList coordinates = string.split( ' ' );
if ( coordinates.size() != 2 )
{
coordinates = string.split( ',' );
}

if ( coordinates.size() == 2 )
QRegularExpression separatorRx( QStringLiteral( "^([0-9\\-\\.]*)[\\s\\,]*([0-9\\-\\.]*)$" ) );
QRegularExpressionMatch match = separatorRx.match( string.trimmed() );
if ( match.hasMatch() )
{
bool okX = false;
bool okY = false;
double posX = coordinates.at( 0 ).toDouble( &okX );
double posY = coordinates.at( 1 ).toDouble( &okY );
double posX = match.captured( 1 ).toDouble( &okX );
double posY = match.captured( 2 ).toDouble( &okY );

if ( okX && okY )
{
Expand Down Expand Up @@ -847,7 +843,7 @@ void QgsGotoLocatorFilter::fetchResults( const QString &string, const QgsLocator
if ( !okX && !okY )
{
QRegularExpression locationRx( QStringLiteral( "google.*\\/@([0-9\\-\\.\\,]*)z" ) );
QRegularExpressionMatch match = locationRx.match( string );
match = locationRx.match( string );
if ( match.hasMatch() )
{
QStringList params = match.captured( 1 ).split( ',' );
Expand Down

0 comments on commit 8d7f090

Please sign in to comment.