Search code examples
phpgoogle-mapsstr-replacegoogle-maps-static-api

str_replace is not working properly


Hi im gonna trying to add x,y location to my static google maps image location string that is

$googlemapstatic="http://maps.googleapis.com/maps/api/staticmap?center=(location)&zoom=7&size=1000x1000&markers=color%3ablue|label%3aS|11211&sensor=false&markers=size:mid|color:0x000000|label:1|(location)";

and i have x and y for its latitude and longitude

$koorX='32.323213123';
$koorY='39.3213';

and im using str replace for changing static maps location and marker inside it.

$newlocation=$koorX.','.$koorY;
$googlemapstatic=str_replace('location',$newlocation,$googlemapstatic);

but it shows me different location than input.

<img style='width:15.61cm; height:12.0cm' src=".$googlemapstatic.'>

If i write that x,y manually from browser, it show correct location. I assume that there is some mistake in str_replace function but i couldn't find it.


Solution

  • use

    ini_set('display_errors','on');
    error_reporting(E_ALL);
    

    if deprecated kind of error then try to use str_ireplace

    $newlocation=$koorX.','.$koorY;
    $googlemapstatic=str_ireplace('location',$newlocation,$googlemapstatic);