1

I have a map.html file that contains a script for google maps api v3, i've been trying previously trying to run this script using the webbrowser1.DocumentText and Webbrower1.Document.InvokeScript been unsuccessful.

This time i have the map.html hosted on a website, My objective is been able to modify this html file and then run it on my windows application in order to display a desired address.

below is the code of the map.html which is hosted ex: http://url.com/map.html

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

<script type="text/javascript" src="http://maps.google.com.mx/maps/api/js?sensor=true&language=es"></script>
<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: 16,
            //center: latlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        }

        //var address = document.getElementById("address").value;
        var address = "Miami Beach, Flordia" //Address to modify in order to display

        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);
            }
        });

        map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
    }


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

  </body>
</html>

if you copy and paste this code in a html it should display Miami Beach, FL

now on my windows application i want to edit this html that is hosted on a website i want to change Miami Beach, Florida to Naples,Florida as an example.

then use a webbrowser on my windows application and display it as Webbrowser1.Navigate("http://url.com/map.html")

your help is very appreciated it.

I did found how to modify an html when it is saved locally on my computer but for what i exactly need this is not a viable way.

thank you,

Leo P.

1 Answer 1

0

I would not try to modify the html code. Since the Google Maps code is all JS, I would write a JS function to move the map to the new location. You can call that function from your application (or even insert it from there).

using mshtml;

//First, navigate to your page:
Webbrowser1.Navigate("http://url.com/map.html")


void Webbrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
        //Then call your move function with the new target:
        mshtml.IHTMLDocument2 doc = (mshtml.IHTMLDocument2)Webbrowser1.Document.DomDocument;
        mshtml.IHTMLWindow2 window = (mshtml.IHTMLWindow2)doc.parentWindow;
        window.execScript("yourMapMoveFunction('Naples,Florida');");
}

BTW, your link does not show a map...

Sign up to request clarification or add additional context in comments.

1 Comment

someone helped me solve this on another post, in which i was actually trying to run the whole script on webbrowser. his solution also applies to this question. "stackoverflow.com/questions/11705729/…" thank you so much for your help !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.