Discussion Board

Results 1 to 3 of 3
  1. #1
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Help using google local search api

    Hi guys i have developing an app based on the example shown here
    i have this now set up to run on a button click from the main html page however...i have tried absoulutly everything to include the google local search api to also run when the map loads.

    Problems i have encountered are:

    map loading with no search results
    map not loading just showing grey box with no map
    javascript errors

    i would like the app to show the map with local search markers already in place without the local search box displayed
    so when the user clicks on the button on the html page it automatically opens the map with the local search markers for local pubs for example

    if anyone can help or needs clarification on what i mean it would be much appretiated

  2. #2
    Nokia Developer Champion
    Join Date
    Nov 2007
    Location
    Rome, Italy
    Posts
    2,406

    Re: Help using google local search api

    Hi specopkirbs,

    try posting the code you've used to integrate Google Local Search API in your widget, so that it'll be possible to spot out possible issues with that.

    Pit

  3. #3
    Registered User
    Join Date
    Oct 2009
    Posts
    2

    Re: Help using google local search api

    Quote Originally Posted by jappit View Post
    Hi specopkirbs,

    try posting the code you've used to integrate Google Local Search API in your widget, so that it'll be possible to spot out possible issues with that.

    Pit
    To be a bit more specific i have tried numerous different codes and cant get any to work...if some one could point me in the right direction that would be awesome here is the google js code:

    Code:
    /*
    *  How to build a Google Map and bind a SearchControl to it and put markers
    *  on the map for each result we receive.
    */
    
    // First, we have to load the APIs.
    google.load('maps' , '2');
    google.load('search' , '1');
    
    // Global variables we will set in OnLoad
    var map;
    var searcher;
    
    // Second, we set up our function, OnLoad
    function OnLoad() {
      // Get the content div and clear it's current contents.
      var contentDiv = document.getElementById('content');
      contentDiv.innerHTML = ''; // Clear any content currently in the Div
    
      // Next thing we have to do is build two divs to hold our stuff
      var mapContainer = document.createElement('div'); // build the map div
      mapContainer.style.height = '350px'; // set the map height
      mapContainer.style.width = '350px'; // set the map width
    
      var controlContainer = document.createElement('div'); // build the control div
      controlContainer.style.width = '350px'; // set the control width
    
      // Now we have to add these divs to the content div in the document body
      contentDiv.appendChild(mapContainer);
      contentDiv.appendChild(controlContainer);
    
      // We're ready to build our map...
      map = new google.maps.Map2(mapContainer);
    
      // ...and add a couple of controls.
      map.addControl(new google.maps.SmallMapControl()); // Add a small map control
      map.addControl(new google.maps.MapTypeControl()); // Add the map type control
    
      // We'll wait to the end to actually initialize the map
      // So let's build the search control
      var searchControl = new google.search.SearchControl();
    
      // Initialize a LocalSearch instance
      searcher = new google.search.LocalSearch(); // create the object
      searcher.setCenterPoint(map); // bind the searcher to the map
    
      // Create a SearcherOptions object to ensure we can see all results
      var options = new google.search.SearcherOptions(); // create the object
      options.setExpandMode(google.search.SearchControl.EXPAND_MODE_OPEN);
    
      // Add the searcher to the SearchControl
      searchControl.addSearcher(searcher , options);
    
     // And second, we need is a search complete callback!
      searchControl.setSearchCompleteCallback(searcher , function() {
        map.clearOverlays();
        var results = searcher.results; // Grab the results array
        // We loop through to get the points
        for (var i = 0; i < results.length; i++) {
          var result = results[i]; // Get the specific result
          var markerLatLng = new google.maps.LatLng(parseFloat(result.lat),
                                                    parseFloat(result.lng));
          var marker = new google.maps.Marker(markerLatLng); // Create the marker
    
          // Bind information for the infoWindow aka the map marker popup
          marker.bindInfoWindow(result.html.cloneNode(true));
          result.marker = marker; // bind the marker to the result
          map.addOverlay(marker); // add the marker to the map
        }
    
        // Store where the map should be centered
        var center = searcher.resultViewport.center;
    
        // Calculate what the zoom level should be
        var ne = new google.maps.LatLng(searcher.resultViewport.ne.lat,
                                        searcher.resultViewport.ne.lng);
        var sw = new google.maps.LatLng(searcher.resultViewport.sw.lat,
                                        searcher.resultViewport.sw.lng);
        var bounds = new google.maps.LatLngBounds(sw, ne);
        var zoom = map.getBoundsZoomLevel(bounds, new google.maps.Size(350, 350));
    
        // Set the new center of the map
        // parseFloat converts the lat/lng from a string to a float, which is what
        // the LatLng constructor takes.
        map.setCenter(new google.maps.LatLng(parseFloat(center.lat),
                                             parseFloat(center.lng)),
                                             zoom);
      });
    
      // Draw the control
      searchControl.draw(controlContainer);
    
      // Set the map's center point and finish!
      map.setCenter(new google.maps.LatLng(37.443915 , -122.163610), 11);
    
     // Execute an initial search
      searchControl.execute('pizza');
    }
    
    google.setOnLoadCallback(OnLoad);
    and here is the code im now using to pull my location:

    Code:
    var so;
     
    try {
        //Retrieves the Service object to the ILocation interface
        so = device.getServiceObject("Service.Location", "ILocation");
    } catch (e) {
        alert(' ' +e);
    }
     
     
    // Gets the GPS position
    function getLocationAsync() {
        // This specifies update option used while retrieving location estimation. 
        var updateoptions = new Object();
        // Setting PartialUpdates to 'FALSE' ensures that user get atleast 
        // BasicLocationInformation (Longitude, Lattitude, and Altitude.) is the default when no LocationInformationClass criteria is given.
        updateoptions.PartialUpdates = false;
     
        var criteria = new Object();
     
        criteria.Updateoptions = updateoptions;
     
        try {
        //Executes the GetLocation method and sets the callbackLocation as the callback function to be called.
        so.ILocation.GetLocation(criteria,callbackLocation);
        } catch (e) {
            alert ("getLocationAsync: " + e);
        }
    }
     
    //Callback function that receives the result as parameter.
    function callbackLocation(transId, eventCode, result){
        var latitude = result.ReturnValue.Latitude;
        var longitude = result.ReturnValue.Longitude;
    }
    To be perfectly honest im pretty new to js and am not sure how to combine the two...im sure its something simple but just cant seem to crack it.

    thanks in advance guys

    chris

Similar Threads

  1. PC Suite error: (Code: Init IMediaControl2) HELP?!
    By chunkyspudmonkey in forum General Development Questions
    Replies: 30
    Last Post: 2014-07-15, 05:44
  2. Replies: 3
    Last Post: 2009-09-25, 07:51
  3. J2ME Google Maps API access problem
    By elaltaico in forum Mobile Java General
    Replies: 5
    Last Post: 2009-05-20, 07:16

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×