www.webdeveloper.com
Results 1 to 6 of 6

Thread: geolocation / get and submit gps-coordinates properly

  1. #1
    Join Date
    Jan 2018
    Posts
    3

    Smile geolocation / get and submit gps-coordinates properly

    Hi Guys!

    I'm adapting an existing Template and my Question regards Geolocation:

    i've got a peice of code, where i can set the center of the Map in my template:

    <script>
    var _latitude = 48.2082647;
    var _longitude = 16.37392060000002;
    </script>


    i'd like to get the current Position of the user and replace the variables _latitude and _longitude with the dynamicly generated coordinates.

    i know only the basics in Javascript and was able to GET the present user-coordinates but i'm not able to replace the values in the script above.
    Could anybody help me out with a script getting AND replacing the coordinates?


    thanks in advance,
    manuel

  2. #2
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,769
    You are talking about a library of some sort, not JavaScript.

    Geo-location, as I ahve experienced this myself, is no good at pinpointing a location. When I was a BT customer many years ago, my ISP being a UK ISP used Yahoo for its email and website, as such I was under constant battle to get yahoo to show my true location and most of the time I was seen as a US visitor on websites as my IP address was allocated in a block that was assigned to yahoo in the US and not in the UK.

    Even with an ISP based in the UK, my IP address with one provider was often seen to be 200 miles from my location as is pretty much the same with my current ISP, according to geo-location, I am based somewhere in North London which is about a 3 hour drive in moving traffic.

    So geo-location is still now a pretty poor system to be investing time and effort in to using.

    GPS is something that you need the permission of the user to obtain and access...

    As for the help you want, you need to state what framework / library / api or widget you are using for your project.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  3. #3
    Join Date
    Jan 2018
    Posts
    3
    there are lots of simple Examples of getting the coordinates (of course with the permission of the user).

    My problem is to connect a script like this:

    <body>
    <p>Click the button to get your coordinates.</p>
    <button onclick="getLocation()">Try It</button>
    <p id="demo"></p>

    <script>
    var x = document.getElementById("demo");

    function getLocation() {
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
    } else {
    x.innerHTML = "Geolocation is not supported by this browser.";
    }
    }

    function showPosition(position) {
    x.innerHTML = "Latitude: " + position.coords.latitude +
    "<br>Longitude: " + position.coords.longitude;
    }
    </script>
    </body>

    …with my existing framework and replace the generated coordinates (above) with the ones, defined as variables here:

    <script>
    var _latitude = 48.2082647;
    var _longitude = 16.37392060000002;
    </script>

    i hope i could explain my problem in a better way now,
    cheers, manuel

  4. #4
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,769
    a framework, api or widget is a script that is written in a language like JavaScript but it isn't JavaScript, its not able to run without a library being included.

    So when someone says framework, they are talking about the library / thing that they include and have written the script in, its not JavaScript.

    So JQuery, Mootools, Prototype, and many others.

    As for your request, it is pretty easy to populate the variables with the results, instead of
    Code:
    if (navigator.geolocation) {
    navigator.geolocation.getCurrentPosition(showPosition);
    ...
    ...
    actually do something with the data like return the values or the error message...

    Its no use calling navigator.geolocation.getCurrentPosition(showPosition); if you are not going to return the data or put the data in to another variable or function, that will be the fundamental problem here.

    You also have the issue over geolocation requests, I always deny because nearly all sites that implement geo-location that I have come across really have no need for using it, meaning I can not see a legitimate reason for knowing where I am, all they need to know is I am from the UK, in fact, theirs very little reason for a website to know your location... period. Those sites that need to know are requiring the data as a matter of security BUT even that is not 100% secure because locations can be spoofed and often are to access content thats restricted in one country, people will find ways to circumvent the restrictions.

    It would be much more simpler if you asked the person if they don't mind stating where they are from in the sign up process but not make it a requirement as you really have to respect peoples privacy which is why any geolocation request is an allow or deny affair.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

  5. #5
    Join Date
    Jan 2018
    Posts
    3
    Thanks for your quick reply!

    i dont want to change as little as possible in my template, so it would be the easiest way to just change the gps-coordinates. The Project is about locations on a map near the user, so it makes sense, that the map shows the area around the user.

    i really know little about the syntax and what all these commands really mean. i just see that it is possible to get coordinates and there should be a easy way to send them / replace them with the defined ones (and if possible use the given coordinates as fallback if georequest is denied).

    i tried to copy/paste script bits and pieces for 2 Days now, but its not working. and there is no way for me to check if it is a fundamental code problem or just a missing dot somewhere…

    so i thought maybe someone could show me ho to get gps coordinates and then send/replace them in my script.

    thanks,
    manuel

  6. #6
    Join Date
    Mar 2007
    Location
    localhost
    Posts
    5,769
    Exactly as I said, use the data you have from the function you invoked, at present its doing nothing, calling the function but the data result is being dumped and not used.
    This line here...
    Code:
    navigator.geolocation.getCurrentPosition(showPosition);
    is called but you have not done anything with it.

    https://developer.mozilla.org/en-US/...urrentPosition

    navigator.geolocation.getCurrentPosition(success, error, options); shows three parameters, success being a function that gets called, as is error and options is an object of parameters.

    To get the data in to your variables, you would use the same type of call but in the function, you set your variables and remember when you var in a function, its data is lost when the function ceases, so you need to have global variables for this to work unless you take another approach.
    --> JavaScript Frameworks like JQuery, Angular, Node <--
    ... and please remember to wrap code with forum BBCode tags:-

    [CODE]...[/CODE] [HTML]...[/HTML] [PHP]...[/PHP]

    If you can't think outside the box, you will be trapped forever with no escape...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.16987 seconds
  • Memory Usage 2,901KB
  • Queries Executed 16 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (2)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (6)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (6)postbit
  • (6)postbit_onlinestatus
  • (6)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (72):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates