1
function show_map(){
    if (isset($_GET["w1"]) && isset($_GET["w2"])){
        $w1=$_GET["w1"];
        $w2=$_GET["w2"];
        echo $w1;
        echo $w2;
        $this->load->library('googlemaps');
        $config=array();
        $config['center']='$w1 $w2';
        $this->googlemaps->initialize($config);

        $marker=array();
        $marker['position']='$w1 $w2';
        $this->googlemaps->add_marker($marker);

        $data['map']=$this->googlemaps->create_map();

        $this->load->view('showmap',$data);
    }
}

I got w1 and w2 from javascript where i used some javascript codes to get my current location.

I have a variable $w1 which has latitude and $w2 which has longitude and now I cannot provide these variables as the map center point.

Map center syntax is: $config['center']='latitude longitude', I have tried this: $config['center']='$w1 $w2'; but it doesn't work.

I'm using php codeigniter.

António Almeida
  • 9,620
  • 8
  • 59
  • 66
Nabin
  • 166
  • 3
  • 11

2 Answers2

1
$config['center'] = $w1 . ' ' . $w2;//use the dot to concatenate the strings
$marker['position']=$w1. ' ' . $w2';
Coding Enthusiast
  • 3,865
  • 1
  • 27
  • 50
0

you are tired with wrong variable assign.

this should work perfectly

function show_map(){
    if (isset($_GET["w1"]) && isset($_GET["w2"])){
        $w1=$_GET["w1"];
        $w2=$_GET["w2"];
        echo $w1;
        echo $w2;
        $this->load->library('googlemaps');
        $config=array();
        $config['center']=$w1.''.$w2;//or can use '$w1'.''.'$w2'
        $this->googlemaps->initialize($config);

        $marker=array();
        $marker['position']=$w1.''.$w2;//change here too
        $this->googlemaps->add_marker($marker);    
        $data['map']=$this->googlemaps->create_map();    
        $this->load->view('showmap',$data);
    }
}

How to combine two strings together

Community
  • 1
  • 1
Abdulla Nilam
  • 36,589
  • 17
  • 64
  • 85