Google Maps questions

@Mittineague,

I tried following the first link in Post #15.

Here is what I have…

    <!-- JavaScript for Google Maps -->
    <script src="https://maps.googleapis.com/maps/api/js"></script>
    <script>
        function initialize(){
            var myLatLng = new google.maps.LatLng(47.702951, -122.277713);
            var mapOptions = {
                zoom: 15,
                center: myLatLng
            }
            var mapCanvas = document.getElementById('map-canvas');
            var map = new google.maps.Map(mapCanvas, mapOptions);
            var marker = new google.maps.Marker({
                position: myLatlng,
                map: map,
                title: 'Hello World!'
            });
        }
        
        google.maps.event.addDomListener(window, 'load', initialize);
    </script>

I still have the same issue of no marker… :confused:

If you look at

you can see that your code isn’t all that different

function initialize() {
  var myLatlng = new google.maps.LatLng(-25.363882,131.044922);
  var mapOptions = {
    zoom: 4,
    center: myLatlng
  }
  var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);

  var marker = new google.maps.Marker({
      position: myLatlng,
      map: map,
      title: 'Hello World!'
  });
}

google.maps.event.addDomListener(window, 'load', initialize);

Exceptions being that LatLng () is assigned to a variable so that it can be reused without needing to do the whole bit again every place it’s used (granted, only two places here, but a good habit to get into). And it has

var marker = new google.maps.Marker({
    position: myLatlng,
    map: map,
    title: 'Hello World!'
});

Inside initialize() just before the closing curly brace

@Mittineague,

See my Post #21 - we were posting at the same time!

Ah, I didn’t spot that before. You left of the ?key=API_KEY

Or try
script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

AFAIK the Key is needed for “work” and without there are usage limits

My code is limited use so I’ve not worried about it.

Getting a “key” requires a Google Developer account which I don’t have and am not really ready to set up.

Is that what the problem is with my missing marker? (Seems rather strange!)

I tried this and it didn’t help…

script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>

Hmmm, If you go to the URL do you see the JavaScript code?

Maybe try “Save As” to your localhost and then reference it like
<script src="../includes/googlemap-v3.js"></script>

Not unless you’ve been requesting it a whole lot in which case they may have shut you off for a while

Another famous case of ONE CHARACTER killing things!!

I had myLatlng instead of myLatLng :smirk:

1 Like

So now that I have a map of the neighborhood where my client’s shop is, and there is a balloon to show his address, what else can I do to provide value to people visiting his website?

Earlier someone said that if you click on the balloon it should give you a prompt to enter your address so you can get directions to his shop.

I tried this and it doesn’t work.

How would I add that feature to this map?

The example seems a bit big for me, but I’m sure it could be just about any HTML you want (in a div).

That just adds a popup with notes in it. Not of much use.

I read this link but it doesn’t tell you how to add in Latitude and Longitude, not how I would tie to together with the existing code I have.

https://developers.google.com/maps/documentation/directions/

Sorry, but not knowing JavaScript or Google API’s puts me at quite a disadvantage.

(I’m surprised there isn’t a simple copy & paste set of code out there to do what I want.)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.