Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. c# windows form & google api v3

c# windows form & google api v3

Scheduled Pinned Locked Moved C#
questioncsharpjavascriptjson
10 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    mrx100
    wrote on last edited by
    #1

    hi all, i use c# windows form application & i want to change latitude & longitude in google api v3 JavaScript code var myLatlng = new google.maps.LatLng(30.050144, 31.240042); according to C# form latitude text box & longitude text box entered value I can display the page in webbrowser control but it's static how can i do this??? thanks in advance

    L L 2 Replies Last reply
    0
    • M mrx100

      hi all, i use c# windows form application & i want to change latitude & longitude in google api v3 JavaScript code var myLatlng = new google.maps.LatLng(30.050144, 31.240042); according to C# form latitude text box & longitude text box entered value I can display the page in webbrowser control but it's static how can i do this??? thanks in advance

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      This is the third time you have asked this question but you have not explained which part does not work.

      Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

      M 1 Reply Last reply
      0
      • L Lost User

        This is the third time you have asked this question but you have not explained which part does not work.

        Binding 100,000 items to a list box can be just silly regardless of what pattern you are following. Jeremy Likness

        M Offline
        M Offline
        mrx100
        wrote on last edited by
        #3

        var myLatlng = new google.maps.LatLng(30.050144, 31.240042); this javascript code works but, i want to replace the static values of latitude (30.050144) & longitude (31.240042) in javascript code with any value entered by user in latitude textbox & longitude textbox

        M 1 Reply Last reply
        0
        • M mrx100

          var myLatlng = new google.maps.LatLng(30.050144, 31.240042); this javascript code works but, i want to replace the static values of latitude (30.050144) & longitude (31.240042) in javascript code with any value entered by user in latitude textbox & longitude textbox

          M Offline
          M Offline
          mrx100
          wrote on last edited by
          #4

          this code i use in html page <%--!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> --%>   html { height: 100% } body { height: 100%; margin: 0; padding: 0 } #map_canvas { height: 100% } function initialize() { var myOptions = { center: new google.maps.LatLng(30.04866, 31.23688), zoom: 8, mapTypeId: google.maps.MapTypeId.ROADMAP }; var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var myLatlng = new google.maps.LatLng(30.050144, 31.240042); var myOptions = { zoom: 20, center: myLatlng, mapTypeId: google.maps.MapTypeId.ROADMAP } var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions); var marker = new google.maps.Marker({ position: myLatlng, map: map, title: "Hello World!" }); }

          & this code i have used in c# form StringBuilder queryAddress = new StringBuilder(); queryAddress.Append("file:///C:/Users/mrx1000/documents/visual studio 2010/Projects/testgoogleapi3/testgoogleapi/HTMLPage1.htm"); webBrowser1.Navigate(queryAddress.ToString()); this image for my form in running http://www.mediafire.com/?rqckg28xb4rlahb as you see i didn't enter anything in latitude text box or longitude text box i find away but it's very difficult in this example & when i use it gives me errors // webBrowser1.DocumentText = //"" + //"function test(message) { alert(message); }" + //"" + //""; what i should i do now?

          1 Reply Last reply
          0
          • M mrx100

            hi all, i use c# windows form application & i want to change latitude & longitude in google api v3 JavaScript code var myLatlng = new google.maps.LatLng(30.050144, 31.240042); according to C# form latitude text box & longitude text box entered value I can display the page in webbrowser control but it's static how can i do this??? thanks in advance

            L Offline
            L Offline
            loyal ginger
            wrote on last edited by
            #5

            Your C# WinForm application with webbrowser control embedded in the form can use the following ways to achieve two-way communication between your C# code and the JavaScript code loaded by the webbrowser control. From JavaScript to C#, follow these steps: 1. Create a member function in C#. In this example, suppose we have a function called "report_location":

            public void **report\_location**(double latitude, double longitude)
            {
            	//you can do whatever you want to do in your C# function here
            }
            

            2. From your JavaScript code whenever you need to call the above C# function, do it like this:

            window.external.**report\_location**(...);
            

            In the above function call the "**...**" represents the arguments you pass to the function. Use whatever arguments you need to use. For example if you are using Google Maps API and you add a listener to the map's click event, the function will be like this:

            google.maps.event.addListener(
            	map,
            	'click',
            	function(event){
            		window.external.**report\_location**(
            			event.latLng.lat(),
            			event.latLng.lng()
            		);
            	}
            );
            

            Your C# code will be able to get the clicked location's latitude/longitude. From C# to JavaScript, follow these steps: (These will answer your specific question.) 1. In your JavaScript code create a function. In this example, suppose we have a function called "set_location":

            function **set\_location**(latitude, longitude){
            	//this is your existing statement
            	//var myLatlng = new google.maps.LatLng(30.050144, 31.240042);
            	//this is the new statement
            	var myLatlng = new google.maps.LatLng(latitude, longitude);
            	//do whatever you want to do...
            }
            

            2. In your C# code whenever you need to call the above function to set the location, do it like this (suppose your webbrowser control is represented by the variable **wb_map**:

            wb\_map.Document.InvokeScript(
            	"**set\_location**",
            	new string\[\]{
            		"30.050144",
            		"31.240042"
            	}
            );
            

            Of course if the numbers are stored in variables such as **latitude**, **longitude**, the above call will be

            wb\_map.Document.InvokeScript(
            	"**set\_location**",
            	new string\[\]{
            		latitude.ToString(),
            		longitude.ToString()
            	}
            );
            

            Hope this answers your question. Happy programming!

            M 1 Reply Last reply
            0
            • L loyal ginger

              Your C# WinForm application with webbrowser control embedded in the form can use the following ways to achieve two-way communication between your C# code and the JavaScript code loaded by the webbrowser control. From JavaScript to C#, follow these steps: 1. Create a member function in C#. In this example, suppose we have a function called "report_location":

              public void **report\_location**(double latitude, double longitude)
              {
              	//you can do whatever you want to do in your C# function here
              }
              

              2. From your JavaScript code whenever you need to call the above C# function, do it like this:

              window.external.**report\_location**(...);
              

              In the above function call the "**...**" represents the arguments you pass to the function. Use whatever arguments you need to use. For example if you are using Google Maps API and you add a listener to the map's click event, the function will be like this:

              google.maps.event.addListener(
              	map,
              	'click',
              	function(event){
              		window.external.**report\_location**(
              			event.latLng.lat(),
              			event.latLng.lng()
              		);
              	}
              );
              

              Your C# code will be able to get the clicked location's latitude/longitude. From C# to JavaScript, follow these steps: (These will answer your specific question.) 1. In your JavaScript code create a function. In this example, suppose we have a function called "set_location":

              function **set\_location**(latitude, longitude){
              	//this is your existing statement
              	//var myLatlng = new google.maps.LatLng(30.050144, 31.240042);
              	//this is the new statement
              	var myLatlng = new google.maps.LatLng(latitude, longitude);
              	//do whatever you want to do...
              }
              

              2. In your C# code whenever you need to call the above function to set the location, do it like this (suppose your webbrowser control is represented by the variable **wb_map**:

              wb\_map.Document.InvokeScript(
              	"**set\_location**",
              	new string\[\]{
              		"30.050144",
              		"31.240042"
              	}
              );
              

              Of course if the numbers are stored in variables such as **latitude**, **longitude**, the above call will be

              wb\_map.Document.InvokeScript(
              	"**set\_location**",
              	new string\[\]{
              		latitude.ToString(),
              		longitude.ToString()
              	}
              );
              

              Hope this answers your question. Happy programming!

              M Offline
              M Offline
              mrx100
              wrote on last edited by
              #6

              loyal ginger wrote:

              wb_map.Document.InvokeScript( "set_location", new string[]{ "30.050144", "31.240042" } );

              thanks for this simple & great answer but when i use this code i have this error object reference not set to an instance of an object

              L 1 Reply Last reply
              0
              • M mrx100

                loyal ginger wrote:

                wb_map.Document.InvokeScript( "set_location", new string[]{ "30.050144", "31.240042" } );

                thanks for this simple & great answer but when i use this code i have this error object reference not set to an instance of an object

                L Offline
                L Offline
                loyal ginger
                wrote on last edited by
                #7

                In my example, wb_map is the WebBrowser control on the Form. You need to replace it with the WebBrowser control in your application.

                M 1 Reply Last reply
                0
                • L loyal ginger

                  In my example, wb_map is the WebBrowser control on the Form. You need to replace it with the WebBrowser control in your application.

                  M Offline
                  M Offline
                  mrx100
                  wrote on last edited by
                  #8

                  loyal ginger wrote:

                  In my example, wb_map is the WebBrowser control on the Form. You need to replace it with the WebBrowser control in your application

                  of course i replace wb_map by webBrowser1 control but i have error i don't know what causes this error object reference not set to an instance of an object ????!!!!!!!!!!!

                  L 1 Reply Last reply
                  0
                  • M mrx100

                    loyal ginger wrote:

                    In my example, wb_map is the WebBrowser control on the Form. You need to replace it with the WebBrowser control in your application

                    of course i replace wb_map by webBrowser1 control but i have error i don't know what causes this error object reference not set to an instance of an object ????!!!!!!!!!!!

                    L Offline
                    L Offline
                    loyal ginger
                    wrote on last edited by
                    #9

                    Sorry I might have misunderstood you. In that case I really have no clue what went wrong. My original reply to your question was based on my error-free application, which happens to be very similar to your program. I don't have a complete picture of your program so it's hard for me to trouble shoot your program. Maybe somebody else here can give you a better answer? Thanks for your patience!

                    M 1 Reply Last reply
                    0
                    • L loyal ginger

                      Sorry I might have misunderstood you. In that case I really have no clue what went wrong. My original reply to your question was based on my error-free application, which happens to be very similar to your program. I don't have a complete picture of your program so it's hard for me to trouble shoot your program. Maybe somebody else here can give you a better answer? Thanks for your patience!

                      M Offline
                      M Offline
                      mrx100
                      wrote on last edited by
                      #10

                      when i put this line of code in webbrowser control it works thanks for all for answers :) if (e.Url.Equals(webBrowser1.Url)) { webBrowser1.Document.InvokeScript("initialize", new object[] { latitude, longitude }); }

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups