On May 5, 3:21 pm, David K-C <[email protected]> wrote:
> Hi Everyone,
>
> I have a list of longitudes and latitudes stored in a mysql database
> that I want to display when a certain record is accessed.
>
> I have tried to include the php variables inside the map javascript
> like this:
>
>     var hlat = '<?php echo $lat; ?>';
>     var hlng = '<?php echo $lng; ?>';
>
> but this does not seem to work. Can anyone explain how I'd do this and
> where I'm going wrong?

That results in
 var hlat = '';
 var hlng = '';
that is, it's not outputting anything at all.

That indicates that at the point where those PHP statements are
executed in your server script, $lat and $lng have not been assigned a
useful value. Not sure how we can help with server-side code.

What can be said is that hlat and hlng should not be used as strings,
nor can you assign variables as in this line:
  map.setCenter(point = new GLatLng(hlat, hlng), 14);
because that uses the result of that assignment [true] as the first
argument for setCenter(), not the GLatLng. It should be
  map.setCenter(new GLatLng(parseFloat(hlat),parseFloat(hlng)), 14);
which uses a GLatLng as the first argument, and makes sure that the
numbers used by the GLatLng really are numbers.

...although that isn't going to work until your server-side code
actually outputs something useful. You could strengthen your code as
  map.setCenter(new GLatLng(parseFloat(hlat)||0,parseFloat(hlng)||0),
14);
which will centre the map at (0,0) in the Atlantic, but it will at
least continue to work.

-- 
You received this message because you are subscribed to the Google Groups 
"Google Maps API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-maps-api?hl=en.

Reply via email to