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#Geocoding
Working demo: http://code.google.com/apis/maps/documentation/javascript/examples/geocoding-simple.html
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)
);
For one, don’t add big gobs of JavaScript inline like that. Put the code in another file and use drupal_add_js() to add the file.
For two, if you’re going to ignore that, note that the single quote in the line that starts with
geocoder.geocodeis ending the string. Everything after that is confusing the parser.