'Bing Map ') ); } //front end public function widget( $args, $instance ){ $title = apply_filters( 'widget_title', $instance['title'] ); echo $args['before_widget']; if( ! empty( $title ) ){ echo $args['before_title'].$title.$args['after_title']; } //this is where you display the content of the widget $display = "
"; echo $display; //---------------------------- echo $args['after_widget']; } //back end public function form( $instance ){ if( isset( $instance['title'] ) ){ $title = $instance['title']; }else{ $title = __('', 'wpb_widget_domain'); } $html_class = $instance['html_class']; ?>"; return $display_map; } function tuskcode_map_putStyleInHeader(){ $css_url = plugins_url('admin/css/style.css?v='.PLUGIN_VERSION , __FILE__); wp_enqueue_style('style', $css_url, 'all'); // echo ''; } function getCoordinates( $add, $key ){ $address = $add; $keyBing = $key; //$prepAddr = urlencode( $prepAddr ); $prepAddr = str_replace(' ','%20',$address); $geocode = file_get_contents('https://dev.virtualearth.net/REST/v1/Locations?q='.$prepAddr.'&o=xml&key='.$keyBing ); $xml = simplexml_load_string( $geocode ); $latitude = ''; $longitude = ''; if( isset( $xml->ResourceSets->ResourceSet->Resources->Location->GeocodePoint->Latitude )){ $latitude = $xml->ResourceSets->ResourceSet->Resources->Location->GeocodePoint->Latitude; $longitude = $xml->ResourceSets->ResourceSet->Resources->Location->GeocodePoint->Longitude; } $arr = array(); if( ($latitude == null) || ($longitude == null) || ($latitude === '') || ( $longitude === '') ){ $arr[0] = ''; $arr[1] = ''; }else{ $arr[0] = $latitude; $arr[1] = $longitude; } return $arr; } function tuskcode_map_putScriptInFooter(){ $img_url = plugins_url('/images/icons/icon1.png', __FILE__ ); $icon_url = plugins_url('/images/icons/'); $map_api_key = get_option('tuskcode_bing_map_api_key', ''); // $map_address = get_option('tuskcode_bing_map_address', ''); $map_width = get_option('tuskcode_bing_map_width', '100%'); $map_height = get_option('tuskcode_bing_map_height', '350px'); $map_pin = get_option('tuskcode_bing_map_pin', 'default.png'); $map_type = get_option('tuskcode_bing_map_type', 'street'); $map_zoom = get_option('tuskcode_bing_map_zoom', '15'); // $map_custom_pin_url = get_option('tuskcode_bing_map_custom_pin_url', ''); $map_scroll = get_option('tuskcode_bing_map_scroll'); $map_pins = get_option('tuskcode_bing_map_pins', '[]'); $map_center_lat = get_option('tuskcode_bing_map_center_lat', '' ); $map_center_long = get_option('tuskcode_bing_map_center_long', '' ); $map_pins = json_decode( $map_pins, true ); // var_dump( $map_pins ); $icon_url = plugins_url('/admin/images/icons/', __FILE__).$map_pin; //get center of the map by finding the median for latitude and longitude; $med_lat = 0; $med_long = 0; //if lat is empty then find the center of the map with valid coordinates $validLocation = 0; if( sizeof( $map_pins ) > 0){ foreach( $map_pins as $pin ){ $med_lat += doubleval( $pin['lat'] ); $med_long += doubleval( $pin['long'] ); if( $pin['lat'] !== '' ){ $validLocation++; } } if( $validLocation > 0){ $med_lat = $med_lat / $validLocation; $med_long = $med_long / $validLocation; } } ?> $value ){ $pin_title = trim( sanitize_text_field( $value )); $pin_desc = preg_replace("/\n/", "bing_map_nl", $pins_desc[ $key ]); $pin_desc = trim( sanitize_text_field( $pin_desc )); $pin_address = trim( sanitize_text_field( $pins_address[ $key ])); $pin_url = trim( esc_attr( $pins_custom_url[ $key ]) ); $bing_pin_latitude = ''; $bing_pin_longitude = ''; if( isset( $_POST['bing_input_latitude']) ){ $bing_pin_latitude = trim($_POST['bing_input_latitude'][ $key ] ); $bing_pin_longitude = trim( $_POST['bing_input_longitude'][ $key ] ); } if( ! empty( $pin_address )){ $coordinates = getCoordinates( $pin_address, $map_api_key ); $pin_lat = strval( json_decode($coordinates[0] ) ); $pin_long = strval( json_decode($coordinates[1]) ); }else{ $pin_lat = $bing_pin_latitude; $pin_long = $bing_pin_longitude; } // || ( ! empty( $pin_desc )) || (! empty( $pin_lat )) || (! empty( $pin_long )) if( ( ! empty( $pin_title ) ) || (! empty( $pin_address)) || ( ! empty( $bing_pin_latitude )) ){ // $pin_arr = [ $pin_title, $pin_desc, $pin_lat, $pin_long, $pin_address, $pin_url ]; // $pins[ $key ] = $pin_arr; $pins[ $key ][ 'title' ] = $pin_title; $pins[ $key ][ 'desc' ] = $pin_desc; $pins[ $key ][ 'lat' ] = $pin_lat; $pins[ $key ][ 'long' ] = $pin_long; $pins[ $key ][ 'address' ] = $pin_address; $pins[ $key ][ 'url' ] = $pin_url; } } $json_pins = json_encode( $pins ); update_option('tuskcode_bing_map_pins', $json_pins ); } }else{ // echo 'not set'; } update_option('tuskcode_bing_map_api_key', $map_api_key ); update_option('tuskcode_bing_map_width', $map_width ); update_option('tuskcode_bing_map_height', $map_height ); update_option('tuskcode_bing_map_pin', $map_pin ); update_option('tuskcode_bing_map_type', $map_type ); update_option('tuskcode_bing_map_zoom', $map_zoom ); update_option('tuskcode_bing_map_class', $map_class ); update_option('tuskcode_bing_map_scroll', $map_scroll ); ?>
Any donations will help me keep plugins free, and develop new ones. Suggestions, or support are welcome at developer@tuskcode.com ----> Credit: Icons are provided by mapicons.mapsmarker.com
Free API Key: www.bingmapsportal.com and follow the instructions!
*** Don't forget to save after making changes ***
"; echo $display; ?> 0){ foreach( $map_pins as $pin ){ $med_lat += doubleval( $pin['lat'] ); $med_long += doubleval( $pin['long'] ); if( $pin['lat'] !== '' ){ $validLocation++; } } if( $validLocation > 0){ $med_lat = $med_lat / $validLocation; $med_long = $med_long / $validLocation; } } ?>