Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Uninitialized string offset #1

Closed
jaska120 opened this issue Jan 16, 2017 · 4 comments
Closed

Uninitialized string offset #1

jaska120 opened this issue Jan 16, 2017 · 4 comments

Comments

@jaska120
Copy link
Contributor

jaska120 commented Jan 16, 2017

When using isLocationOnEdge on several decoded polylines, I am getting error on some encoded polylines: Uninitialized string offset: 156 in PolyUtil.php on line 313, which points to a decoding function. I have escaped all the backslashes from encoded polyline at the time of creating in Javascript, but I am not aware if some characters should be escaped also in PHP.

Encoded polyline, which produces the error is:
polyline_error.txt

@alexpechkarev
Copy link
Owner

Hi @jaska120 ,
Please can you show how you making the call ?

The isLocationOnEdge method only available for Directions API.
Here how this method to be invoked within this package:

$response = \GoogleMaps::load('directions')
            ->setParam([
                'origin'          => 'place_id:ChIJ685WIFYViEgRHlHvBbiD5nE', 
                'destination'     => 'place_id:ChIJA01I-8YVhkgRGJb0fW4UX7Y', 
            ])
           ->isLocationOnEdge(55.86483,-4.25161);

    dd( $response  );  // true

Regards,
Alexander

@jaska120
Copy link
Contributor Author

I am making the call to database where are user previously inserted encoded polylines and point is user defined point to which the query is made against.

$distance = 1000; //meters
$startpoint = array('lat' => 61.487002, 'lng' => 23.790636);
$endpoint = array('lat' => 60.215399, 'lng' => 24.943364);

while($row = $result->fetch_assoc()) {
	$encoded = $row["encodedpolyline"];
	$polyline = \GeometryLibrary\PolyUtil::decode($encoded); 
				
	$startboolean = \GeometryLibrary\PolyUtil::isLocationOnEdge($startpoint,$polyline,$distance);
	$endboolean = \GeometryLibrary\PolyUtil::isLocationOnEdge($endpoint,$polyline,$distance);

        if ($startboolean and $endboolean) {
		//var_dump($encoded);
	        //var_dump($startboolean);
	       //var_dump($endboolean);
	       $data[] = $row;
	}
}

$data array is being JSON encoded and sent to client via Ajax call and it returns correctly except the error occurs with the last polyline. In this example I have provided $startpoint and $endpoint arrays hardcoded but those are the coordinates with which user would face error.

Please find attached txt document for encoded polylines SQL queried from $row["encodedpolyline"]. The problem occurs only with the last polyline and the functions works if I delete that from database so I guess it has something do with the format of encoding.
example_encoded_polylines.txt

@jaska120
Copy link
Contributor Author

Hi Alexander,

My bad, there was still a problem with escaping backslashes and your code is working normally.

Thanks,
Jaska

@alexpechkarev
Copy link
Owner

Hi @jaska120 ,

Thank you for your update, glad to hear that issue has been resolved.

Regards,
Alexander

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants