jsonp
-
Hi,
I find this is a great map plugin, and will purchase this after I’m done setting things up completely in my localost environment.
So far everything was good until I was trying to search for a marker with its markername and update its geocode. To do this, I need to search by markername and get its ID first. Once I get the ID of the marker, then I can update the marker. I can search for a marker, but the response is an array from which I need to parse the marker information such as ID.
Here’s how I search for a marker.
$map_api_url = plugins_url()."/leaflet-maps-marker-pro/leaflet-api.php"; $user_id = $current_user->id; $user_info = get_userdata( $user_id ); $company = $user_info->company_name; $office_address = $user_info->office_address; echo "company = ".$company."<br/>"; $jsonp = wp_remote_post( $map_api_url, array( 'method' => 'POST', 'body' => array( 'key' => '0406', 'signature' => 'JMmfJgmJgNWhWI%2B1915QOGfP4Cw%3D', 'expires' => '1398743380', 'action' => 'search', 'type' => 'marker', 'searchkey' => 'markername', 'searchvalue' => $company ) ) ); if( is_wp_error( $jsonp ) ) { $error_message = $jsonp->get_error_message(); echo "Something went wrong: $error_message"; } else { // Yes, found the marker with the given markername. Now, need to figure out its ID. }
However, what I get as a response is as below, exactly what is described in https://www.mapsmarker.com/docs/api-tutorials/web-api/#response.
Array ( [headers] => Array ( [date] => Mon, 28 Apr 2014 11:41:09 GMT [server] => Apache ....... [content-type] => application/json; charset=utf-8 ) [body] => jsonp({ "success":true, "searchkey":"markername", "searchvalue":"dongsan", "searchresults":1, "message":"Search completed - showing 1 results below", "data": [ {"id":"68", "markername":"dongsan", "basemap":"bingroad", "layer":"1", "lat":"39.904030", "lon":"116.407526", "icon":"", "popuptext":"", "zoom":"11", "openpopup":"1", "mapwidth":"640", ....... "wms10":"0", "kml_timestamp":"", "address":"", "gpx_url":"", "gpx_panel":"0" }]}); [response] => Array ( [code] => 200 [message] => OK ) [cookies] => Array ( [0] => WP_Http_Cookie Object ( [name] => qtrans_cookie_test [value] => qTranslate Cookie Test [expires] => [path] => /wordpress/ [domain] => 127.0.0.1 ) ) [filename] => )
How do I parse this ID from the above array(?) ? I tried json_decode and failed.
Thank you.
- The topic ‘jsonp’ is closed to new replies.