views:

417

answers:

2

I have a relatively simple question that I cannot seem to find the answer for. While doing the Google Maps Java API Tutorials, I ran into a problem. I can load an HTML file from the web, but when I try it locally, it just displays the contents of the file instead of running the script.

Here's what works:

NSString *url = @"http://code.google.com/apis/maps/documentation/v3/examples/geocoding-simple.html";
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]];
[webView loadRequest:request];

I want to store the HTML file locally and run it from the device itself, so I tried:

[webView loadRequest:[NSURLRequest requestWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"geocoding-simple" ofType:@"html"]isDirectory:NO]]]; 

and it just displayed the contents of the file.

Here is the html file:

<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no"/>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps JavaScript API v3 Example: Geocoding Simple</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"&gt;&lt;/script&gt;
<script type="text/javascript">
  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);
  }

  function codeAddress() {
    var address = document.getElementById("address").value;
    if (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);
        }
      });
    }
  }
</script>
</head>
<body style="margin:0px; padding:0px;" onload="initialize()">
  <div>
    <input id="address" type="textbox" value="Sydney, NSW">
    <input type="button" value="Geocode" onclick="codeAddress()">

  </div>
<div id="map_canvas" style="width:100%; height:90%"></div>
</body>
</html>

What am I doing wrong here?

Thomas

A: 

OK. I cleaned all targets, and it works now...SWEEEET!

Thomas
A: 

Hello Thomas,

What targets have you cleaned? I have about 12 html pages with javascript, which I would like to show on the phone.

Vasilij
I cleaned all targets. Build << Clean All Targets
Thomas
Thanks, much appriciated. I'll try. I'm doing a free off-line Russian Bible with 1200 pages and with 250 pages for kids. I need to learn more. Spent already a few days and haven't figured out how to make external .js to execute. Found some guidelines on this site, and hope it helps.Thanks again for your answer.
Vasilij