Drupal 7 giving Parse error: syntax error, unexpected T_STRING

1 reply [Last post]
vishalkhialani
Offline
Last seen: 40 weeks 2 hours ago
Joined: 2011-11-08

Goal: To render a google map using geolocation.

I am trying to implement the below example on my site.

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

Working demo: http://code.google.com/apis/maps/documentation/javascript/examples/geoco...

I have implemented the code in my drupal_add_js() in hook_init() but I am getting an error

Parse error: syntax error, unexpected T_STRING in /home/vishal/public_html/dev/sites/all/modules/customvishal/customvishal.module on line 43

below is my code:

drupal_add_js('
var geocoder;
var map;

function initialize()
{
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(-34.397, 150.644);
var myOptions = {
zoom: 8,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);

}

var address = "pune,india";
var latlng = new google.maps.LatLng();
geocoder = new google.maps.Geocoder();

geocoder.geocode( { 'address': address}, function(results, status)
{
if (status == google.maps.GeocoderStatus.OK)
{
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker
({
map: map,
position: results[0].geometry.location
});
}
else
{
alert("Geocode was not successful for the following reason: " + status);
}

}

);

',
array('type' => 'inline', 'scope' => 'header', 'weight' => 5)

);

Drave Robber
Offline
Last seen: 6 years 1 week ago
Joined: 2012-08-07
The js you're trying to add

The js you're trying to add is enclosed in single quotes but contains single quotes within it, leading the parser to find the end of the string where it's not intended. You could try changing those to double quotes:

geocoder.geocode( { "address": address}, function(results, status)

...but generally adding such big chunks inline is not a good idea (hard to debug), better load them from a file.

Add to playlist

Add to , or

Add to new playlist:

Add to playlist
This is a member-only feature
But, it's easy to become a member

Add to cart:


Loading...
Contact us

Below are the supported keyboard shortcuts for our video player.

space
Start / stop video
shift
Go to next video
shift
Go to previous video
Increase or decrease player speed by 20%
Skip ahead or go back by 15 seconds
1...9
Jump to a percentage (2 is 20%, for example)
f
Toggle full screen
Videos Pricing More Search
BuildAModule Logo Icon BuildAModule Logo Icon
Become a member!
$29
1 month
$156
6 months
10% off
$276
12 months
20% off
All memberships come with the following:
24 / 7 access to the entire 1800+ video library
An innovative video player with a rolling transcript
Extensive Drupal and cross-platform training
A thorough and thoughtful training style
Progress tracking
Take notes on specific video sections
Intuitive multi-user management
How many users?
user
Go solo with a single user, or give multiple team members access through one account and get discounts by bundling multiple users into a single membership.