Jump to content

Google Maps API


Recommended Posts

Hi Guys


I am having my first trip into the worlds of google maps api v3.


This far I can generate a map based off a location lookup. This is all just rough to test things out (see code below).


What I am really stuck with is how to get the geocoding to work.


All I want to do is geocode an address and display the new marker on my map. But i can't even get google's example to work :/ Can anyone propose a way to make this work with my little bit of code below?


I've been at this for about four hours so any help would be appreciated  :'(


Google's example code

geocoder = new google.maps.Geocoder();
geocoder.geocode({ 'address': 'london' }, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
    var marker = new google.maps.Marker({
    map: map,
    position: results[0].geometry.location



My Code

<!DOCTYPE html>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
      html { height: 100% }
      body { height: 100%; margin: 0; padding: 0 }
      #map_canvas { height: 100% }
    <script type="text/javascript"
    <script type="text/javascript">

// Innitiate call to get coords

	function getLoc(){

		navigator.geolocation.getCurrentPosition(getCord, errorFunc, {enableHighAccuracy: true});


	// Position check was successful - therefore set vars and call map
	function getCord(position){

		var lat = position.coords.latitude;
		var longe = position.coords.longitude;

		initialize(lat, longe);


	// Report error when finding coords
	function errorFunc(error){

	var error = error.code;


// Initialise the Google Map
      function initialize(lat, longe) {

	var lat = lat;
	var longe = longe;

	var mapOptions = {

          center: new google.maps.LatLng(lat, longe),
          zoom: 8,
          mapTypeId: google.maps.MapTypeId.ROADMAP

        var map = new google.maps.Map(document.getElementById("map_canvas"),

	var marker = new google.maps.Marker({
        position: new google.maps.LatLng(lat, longe),
        map: map,
	title: 'tester'


  <body onload="getLoc()">
    <div id="map_canvas" style="width:100%; height:100%"></div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.