Hello,

I would like help in change a bit the following code. It shows google map, but I would like to show google street view. Can you tell me what I need to do/change? I donĀ“t understand very well code. Thanks in advance.

This is the code:

<?php
// =============================== Google Map Single page======================================
class googlemmap_singlepage extends WP_Widget {
	function googlemmap_singlepage() {
	//Constructor
		$widget_ops = array('classname' => 'widget Google Map in Detail page Sidebar', 'description' => __('Google Map in Detail page Sidebar. It will show you google map V3 for detail page only.') );		
		$this->WP_Widget('googlemmapwidget_single', __('PT &rarr; Google Map V3 - Detail page'), $widget_ops);
	}
	function widget($args, $instance) {
	// prints the widget
		extract($args, EXTR_SKIP);
		$title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
		$advt1 = empty($instance['advt1']) ? '' : apply_filters('widget_advt1', $instance['advt1']);
		$link1 = empty($instance['link1']) ? '' : apply_filters('widget_link1', $instance['link1']);
		 ?>						
 	    
                    	<div class="sidebar_map clearfix">
<?php
global $post,$wp_query;
$post = $wp_query->post;
if(is_single()){
if(get_post_meta($post->ID,'address',true))
{
	$address = get_post_meta($post->ID,'address',true);
}else
{
	$address = get_post_meta($post->ID,'geo_address',true);
}
$address_latitude = get_post_meta($post->ID,'geo_latitude',true);
$address_longitude = get_post_meta($post->ID,'geo_longitude',true);
$map_type = get_post_meta($post->ID,'map_view',true);
if($map_type=='G_NORMAL_MAP')
{
	$map_type='ROADMAP';
}elseif($map_type=='G_SATELLITE_MAP')
{
	$map_type='SATELLITE';
}elseif($map_type=='G_HYBRID_MAP')
{
	$map_type='TERRAIN';
}
$scale = 14;
if( $post->post_type=='post')
{
	$cagInfo = wp_get_object_terms($post->ID,'category',$args);
}else
{
	$cagInfo = wp_get_object_terms($post->ID,'eventcategory',$args);
}

$cat_icon = $cagInfo[count($cagInfo)-1]->term_icon;
if($cat_icon=='')
{
	$cat_icon = '';	
}
$prdimage =  bdw_get_images($post->ID,'thumb',1);

$srch_arr = array("'",'"','\\');
$rpl_arr = array('','','');
$contact = trim(str_replace($srch_arr,$rpl_arr,get_post_meta($post->ID,'contact',true)));
$post_title = trim(str_replace($srch_arr,$rpl_arr,get_the_title($post->ID)));
$address = trim(str_replace($srch_arr,$rpl_arr,$address));

$tooltip_message = '';
$tooltip_message = '<img src="'.$prdimage[0].'" width=90 height=70 style="float:left; margin:0 11px 22px 0;" />';
$tooltip_message .= '<a href="'.get_permalink($post->ID).'" class=ptitle>'.$post_title.'</a>';
if($address){
$tooltip_message .= '<br/><span class=pcontact>'.$address.'</span>';
}
if($contact){
$tooltip_message .= '<br/><span class=pcontact>'.wordwrap($contact,40,'<br/>\n').'</span>';
}				
if($address_longitude && $address_latitude)
{
?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
	var mapDiv = document.getElementById('map-canvas');
	var latLng = new google.maps.LatLng(<?php echo $address_latitude;?>, <?php echo $address_longitude;?>);
	var map = new google.maps.Map(mapDiv, {
	  center: latLng,
	  zoom: <?php echo $scale;?>,
	  <?php if($map_type=='ROADMAP' || $map_type=='SATELLITE'|| $map_type=='TERRAIN'){?>
	 mapTypeId: google.maps.MapTypeId.<?php echo $map_type;?>,
	 <?php }else{?>
	 mapTypeId: google.maps.MapTypeId.ROADMAP,
	 <?php }?>
	});
	
	var image = '<?php echo $cat_icon;?>';
	var myLatLng = new google.maps.LatLng(<?php echo $address_latitude;?>, <?php echo $address_longitude;?>);
	var Marker = new google.maps.Marker({
	  position: latLng,
	  map: map,
	  icon: image
	});

	var content = '<?php echo $tooltip_message;?>';
	infowindow = new google.maps.InfoWindow({
	  content: content
	});
	infowindow.open(map, Marker);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="map-canvas" style="width:294px; height:370px"></div>
<span style="font:bold 12px Arial, Helvetica, sans-serif; font-weight:bold; float:left; display:block; padding:8px;  "><a href="http://maps.google.com/maps?f=d&dirflg=d&saddr=<?php echo $address;?>" target="_blank"><?php _e('Obtener direcciones en el mapa &raquo;');?></a></span>
<?php
	} 
}
?>
</div> 
	<?php
	}
	function update($new_instance, $old_instance) {
	//save the widget
		$instance = $old_instance;		
		$instance['title'] = strip_tags($new_instance['title']);
		$instance['advt1'] = ($new_instance['advt1']);
		$instance['link1'] = ($new_instance['link1']);

		return $instance;
	}
	function form($instance) {
	//widgetform in backend
		$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'advt1' => '', 'link1' => '') );		
		$title = strip_tags($instance['title']);
		$advt1 = ($instance['advt1']);
		$link1 = ($instance['link1']);
	}}
register_widget('googlemmap_singlepage');
?>

Recommended Answers

All 4 Replies

Have a look at the GoogleMaps API: http://code.google.com/apis/maps/index.html

Thanks for your reply. I was looking it, but I am not able to see any change in my web. can any more help me with this, what I need to change exactly..

Thanks in advance

http://code.google.com/apis/maps/documentation/javascript/v2/services.html#StreetviewOverlays

C'mon man, you can search Google as good as anyone right?

You are right!! I was looking at those links you send me, I was trying with this, but all I have is nothing. I had change some code, $map_type = get_post_meta($post->ID,'map_view',true); for: $map_type = get_post_meta($post->ID,'StreetViewPanorama',true);

with those tutorials I was abel to do this, but it does not work, I just see a white space in map section:

<?php
// =============================== Google Map Single page======================================
class googlemmap_singlepage extends WP_Widget {
       function googlemmap_singlepage() {
       //Constructor
               $widget_ops = array('classname' => 'widget Google Map in Detail page Sidebar', 'description' => __('Google Map in Detail page Sidebar. It will show you google map V3 for detail page only.') );
               $this->WP_Widget('googlemmapwidget_single', __('PT &rarr; Google Map V3 - Detail page'), $widget_ops);
       }
       function widget($args, $instance) {
       // prints the widget
               extract($args, EXTR_SKIP);
               $title = empty($instance['title']) ? '' : apply_filters('widget_title', $instance['title']);
               $advt1 = empty($instance['advt1']) ? '' : apply_filters('widget_advt1', $instance['advt1']);
               $link1 = empty($instance['link1']) ? '' : apply_filters('widget_link1', $instance['link1']);
                ?>

                       <div class="sidebar_map clearfix">
<?php
global $post,$wp_query;
$post = $wp_query->post;
if(is_single()){
if(get_post_meta($post->ID,'address',true))
{
       $address = get_post_meta($post->ID,'address',true);
}else
{
       $address = get_post_meta($post->ID,'geo_address',true);
}
$address_latitude = get_post_meta($post->ID,'geo_latitude',true);
$address_longitude = get_post_meta($post->ID,'geo_longitude',true);
$map_type = get_post_meta($post->ID,'map_view',true);
if($map_type=='G_NORMAL_MAP')
{
       $map_type='ROADMAP';
}elseif($map_type=='G_SATELLITE_MAP')
{
       $map_type='SATELLITE';
}elseif($map_type=='G_HYBRID_MAP')
{
       $map_type='TERRAIN';
}
$scale = 14;
if( $post->post_type=='post')
{
       $cagInfo = wp_get_object_terms($post->ID,'category',$args);
}else
{
       $cagInfo = wp_get_object_terms($post->ID,'eventcategory',$args);
}

$cat_icon = $cagInfo[count($cagInfo)-1]->term_icon;
if($cat_icon=='')
{
       $cat_icon = '';
}
//$prdimage =  bdw_get_images($post->ID,'thumb',1);

$srch_arr = array("'",'"','\\');
$rpl_arr = array('','','');
$contact = trim(str_replace($srch_arr,$rpl_arr,get_post_meta($post->ID,'contact',true)));
$post_title = trim(str_replace($srch_arr,$rpl_arr,get_the_title($post->ID)));
$address = trim(str_replace($srch_arr,$rpl_arr,$address));

$tooltip_message = '';
//$tooltip_message = '<img src="'.$prdimage[0].'" width=90 height=70 style="float:left; margin:0 11px 22px 0;" />';
$tooltip_message .= '<a href="'.get_permalink($post->ID).'" class=ptitle>'.$post_title.'</a>';
if($address){
$tooltip_message .= '<br/><span class=pcontact>'.$address.'</span>';
}
if($contact){
$tooltip_message .= '<br/><span class=pcontact>'.wordwrap($contact,40,'<br/>\n').'</span>';
}
if($address_longitude && $address_latitude)
{
?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
function initialize() {
       var panoDiv = document.getElementById('pano-canvas');
       var latLng = new google.maps.LatLng(<?php echo $address_latitude;?>, <?php echo $address_longitude;?>);
   var panoramaOptions = {
     position:latLng,
     pov: {
       heading: 165,
       pitch:0,
       zoom:1
     }
   };
   var myPano = new google.maps.StreetViewPanorama(panoDiv, panoramaOptions);
   myPano.setVisible(true);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div id="pano-canvas" style="width:294px; height:370px"></div>
<span style="font:bold 12px Arial, Helvetica, sans-serif; font-weight:bold; float:left; display:block; padding:8px;  "><a href="http://maps.google.com/maps?f=d&dirflg=d&saddr=<?php echo $address;?>" target="_blank"><?php _e('Obtener direcciones en el mapa &raquo;');?></a></span>
<?php
       }
}
?>
</div>
       <?php
       }
       function update($new_instance, $old_instance) {
       //save the widget
               $instance = $old_instance;
               $instance['title'] = strip_tags($new_instance['title']);
               $instance['advt1'] = ($new_instance['advt1']);
               $instance['link1'] = ($new_instance['link1']);

               return $instance;
       }
       function form($instance) {
       //widgetform in backend
               $instance = wp_parse_args( (array) $instance, array( 'title' => '', 'advt1' => '', 'link1' => '') );
               $title = strip_tags($instance['title']);
               $advt1 = ($instance['advt1']);
               $link1 = ($instance['link1']);
       }
}

function register_googlemmap_singlepage(){
       register_widget('googlemmap_singlepage');
}

add_action('init', 'register_googlemmap_singlepage', 1)


?>

Any help??

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.