views:

65

answers:

1
http://maps.google.com/maps/api/staticmap?center=Berkeley,CA&zoom=14&size=280x280&sensor=false&markers=icon:http://chart.apis.google.com/chart%3Fchst%3Dd_map_spin%26chld%3D1%257C0%257Cfff%257C11%257C_%257CHere|Berkeley,CA

if we open the image above it works well.

http://maps.google.com/maps/api/staticmap?center=cabindeck,Startrack&zoom=14&size=280x280&sensor=false&markers=icon:http://chart.apis.google.com/chart%3Fchst%3Dd_map_spin%26chld%3D1%257C0%257Cfff%257C11%257C_%257CHere|cabindeck,Startrack

the question is how di i give an error echo if it fails ? any ideas ? btw im useing php

like

    function get( $address ){
    echo '<img src="http://maps.google.com/maps/api/staticmap?center=' . $address . '
    &zoom=14&size=280x280&sensor=false&markers=icon:http://chart.apis.google.com/chart%3Fchst%3Dd_map_spin%26chld%3D1%257C0%257Cfff%257C11%257C_%257CHere|' . $address . '" alt="" />';
}
A: 

If you must do it without ajax, the following may work. But it depends on the response curl gets back from google.

function getMap($address){

    //Target Url
    $target = "http://maps.google.com/maps/api/staticmap?center={$address}&amp;zoom=14&amp;size=280x280&amp;sensor=false&amp;markers=icon:http://chart.apis.google.com/chart%3Fchst%3Dd_map_spin%26chld%3D1%257C0%257Cfff%257C11%257C_%257CHere|{$address}";

    //run curl
    $curl_instance = curl_init($target);
    curl_setopt($curl_instance, CURLOPT_RETURNTRANSFER, true);
    curl_exec($curl_instance);

    //if the img did not come back
    if(curl_errno($curl_instance))
        return '<p class="error">Map Error: ' . curl_error($ch) . '</p>';
    else
        return "<img src=\"{$target}\" alt=\"Map\" />";

    //kill curl
    curl_close($curl_instance);
}

echo getMap($address);
Robert Hurst
still not working :) nice try
Adam Ramadhan
anyway $check_size = curl_getinfo( $target, CURLINFO_SIZE_DOWNLOAD ); if ( $check_size == 1350 ) { work :)
Adam Ramadhan